简体   繁体   English

在JSON中现有的双引号内搜索和替换双引号

[英]Search and replace double quotes inside existing double quotes in JSON

I have data that loks like this: 我有这样的数据:

"contributors": null, "truncated": false, "text": "This is "what" we call text", "coordinates": null “贡献者”:null,“截断”:false,“文本”:“这就是我们所说的”文本“”,“坐标”:null

Notice the double quotes inside existing double quotes for the "text" node (bad data, I know). 请注意,“文本”节点的现有双引号内有双引号(我知道是坏数据)。 The data set is HUGE, so manual clean-up would be out of the question. 数据集很大,因此手动清理将是不可能的。 I'm streaming the data using Node.js, so I can do the replace on a line-by-line basis. 我正在使用Node.js传输数据,因此可以逐行进行替换。 Is there any way with JS to escape (or change to single quote) these instances? JS有什么办法可以逃脱(或更改为单引号)这些实例? Any assistance would be appreciated. 任何援助将不胜感激。 Thanks 谢谢

Not with Node.js, since you need a lookbehind assertion to negate valid JSON schema characters ( : and , ). 不适用于Node.js,因为您需要一个后置断言来否定有效的JSON模式字符( :, )。

You could do this though, in something like Python. 不过,您可以使用类似Python的方法执行此操作。 It won't catch everything though, and you'll probably have to do some manual cleanup: 它不会捕获所有内容,并且您可能必须进行一些手动清理:

(?<![:,] )"(?![:,])

Expand on it if you want here: https://regex101.com/r/rB4vV9/1 如果需要,请在此处进行扩展: https : //regex101.com/r/rB4vV9/1

Related: why is your datasource not spitting out valid JSON, and why haven't you gone knocking on the owner's door do tell them they're doing it wrong? 相关:为什么您的数据源没有吐出有效的JSON,为什么您还没有敲开所有者的门却告诉他们他们做错了?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM