Python - 解析半 JSON 格式的文本
我一直在思考一个问题,但我似乎无法找出正确的前进道路,所以这里是。
我正在尝试解析一个配置文件,但它的编写方式与普通的 .conf 文件不同,并且几乎采用 Half-JSON 格式。下面是如何写出数据的示例:
{
TEST {
test1 = "test description"
test2 = "test description 2"
test inner {
innertest = "(something && something)"
innertest2 = """something else"""
}
TEST2 {
test1 = "test description"
test2 = "test description 2"
test inner {
innertest = "(something && something)"
innertest2 = """something else"""
}
}
如您所见,它具有 JSON 的缩进和嵌套,但没有使用普通 JSON 解析器所需的双引号/引号。
有人建议如何将其解析为 python 吗?我的实际最终目标只是使用 Pandas 将特定字段名称(例如 test1、test2)解析到表中,但如果您能想到一种方法可以绕过此问题,请随意提出建议。
I've been mulling over a problem, but I can't seem to figure out the right path forward, so here goes.
I'm attempting to parse a Config file, however it's not written like a normal .conf file, and is almost in a Half-JSON format. Here's an example of how the data is written out:
{
TEST {
test1 = "test description"
test2 = "test description 2"
test inner {
innertest = "(something && something)"
innertest2 = """something else"""
}
TEST2 {
test1 = "test description"
test2 = "test description 2"
test inner {
innertest = "(something && something)"
innertest2 = """something else"""
}
}
As you can see, it's got the indentation and nesting of JSON, but without the double quotes/quotes needed to use the normal JSON parser.
Does anyone have a suggestion on how to parse this into python? My actual end goal was just to parse specific field names (e.g. test1, test2) into a table using Pandas, but if there's a way you can think of that bypasses this, feel free to sugest that also.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论