有没有适用于Python的“宽容”JSON解析器?
我一直在收到这样的(手写)JSON文件:
/* This JSON file is created by someone who does not know JSON
And not competent enough to search about "JSON Validators" */
{
/* Hey look!
A honkin' block comment here!
Yeehaw */
"key1": "value1", // Hey look there's a standard-breaking comment here!
"key3": .65, // I'm too lazy to type "0"
"key4": -.75, // That "other" .Net program works anyways...
"key5": [ 1 /* One */, 2 /* Two */, 3 /* Three */, 4 /* Four */],
"key2": "value2", // Whoopsie, forgot to delete the comma here...
}
那个实际消耗这些异常JSON文件的程序不知何故并没有因这些错误而崩溃。顺便说一下,该程序是用C#编写的。
我正在使用Python编写一些脚本,根据这些JSON文件执行某些操作,但它一直在这些错误上崩溃(正确的)。
我可以手动编辑这些.json文件以符合标准...但是有很多文件,因此这太费力了--更不用说我还必须继续编辑新的JSON文件了,呃。
所以,回到我的问题,是否有一个宽容的JSON解析器可以消耗这些畸形的JSON文件而不会死机?
注意:此问题仅涉及最后一个对象的尾随逗号;它不处理块注释和/或行内注释。
编辑:我刚刚收到一个JSON文件,其中创建者决定删除0<数字<1的前导零... -_-
而且我发现了一个嵌入了注释的文件... :fuming_red:
我将更新上面的示例以反映我的额外“发现”...