在您的输入中添加一些其他奇怪的错误案例
{ "last_modified": {"type": "/type/datetime", "value": "2008-04-01T03:28:50.625462"},
"type": {"key": "/type/author"},
"name": "National Research Council. Committee on the Scientific and Technologic Base of Puerto Rico"s Economy.",
"key": "/authors/OL2108538A",
"revision": 1,
"has \" escaped quote": 1,
"has \" escaped quotes \"": 1,
"has multiple " internal " quotes": 1,
}
这个 Perl 程序使用启发式纠正未转义的内部双引号,即字符串的实际右引号后跟可选的空格和冒号、逗号、分号或花括号
#! /usr/bin/perl -p
s<"(.+?)"(\s*[:,;}])> {
my($text,$terminator) = ($1,$2);
$text =~ s/(?<!\\)"/'/g; # " oh, the irony!
qq["$text"] . $terminator;
}eg;
产生以下输出:
$ ./fixdqs 输入.json
{ "last_modified": {"type": "/type/datetime", "value": "2008-04-01T03:28:50.625462"},
"type": {"key": "/type/author"},
"名称": "国家研究委员会。波多黎各经济科技基础委员会。",
"key": "/authors/OL2108538A",
“修订”:1,
"有 \" 转义引号": 1,
"有 \" 转义引号 \"": 1,
"有多个 ' 内部 ' 引号": 1,
}
从输入到输出的增量:
$ diff -ub input.json <(./fixdqs input.json)
--- 输入.json
+++ /dev/fd/63
@@ -1,9 +1,9 @@
{ "last_modified": {"type": "/type/datetime", "value": "2008-04-01T03:28:50.625462"},
"type": {"key": "/type/author"},
- “名称”:“国家研究委员会。波多黎各经济科技基础委员会。”,
+“名称”:“国家研究委员会。波多黎各经济科技基础委员会。”,
"key": "/authors/OL2108538A",
“修订”:1,
"有 \" 转义引号": 1,
"有 \" 转义引号 \"": 1,
- "有多个 " 内部 " 引号": 1,
+ "有多个 ' 内部 ' 引号": 1,
}