我必须修改文件json。我必须用双引号替换单引号,但我不能使用以下命令sed -i -r "s/'/\"/g" file
,因为在文件中有更多单引号不会更改。用括号中的双引号替换单引号
以下代码是串的一个例子:
"categories": [['Clothing, Shoes & Jewelry', 'Girls'], ['Clothing, Shoes & Jewelry', 'Novelty, Costumes & More', 'Costumes & Accessories', 'More Accessories', 'Kids & Baby']]
的desided结果应该是:
"categories": [["Clothing, Shoes & Jewelry", "Girls"], ["Clothing, Shoes & Jewelry", "Novelty, Costumes & More", "Costumes & Accessories", "More Accessories", "Kids & Baby"]]
示例文件:
{"categories": [['Movies & TV', 'Movies']], "title": "Understanding Seizures and Epilepsy DVD"},
{"title": "Who on Earth is Tom Baker?", "salesRank": {"Books": 3843450}, "categories": [['Books']]},
{"categories": [['Clothing, Shoes & Jewelry', 'Girls'], ['Clothing, Shoes & Jewelry', 'Novelty, Costumes & More', 'Costumes & Accessories', 'More Accessories', 'Kids & Baby']], "description": "description, "title": "Mog's Kittens", "salesRank": {"Books": 1760368}}},
{"description": "Three Dr. Suess' Puzzles", "brand": "Dr. Seuss", "categories": [['Toys & Games', 'Puzzles', 'Jigsaw Puzzles']]},
我使用的正则表达式,但问题是我不知道括号中有多少元素。所以我想用一种方法来替换括号中的所有单引号,这是一种完美的方式,但我找不到解决方案。
你的意思是,你只能改变报价在给定的直线?你能发布一个(小)完整的json文件吗? –
{“categories”:[[''Movies&TV','Movies']],“title”:“Understanding Seizures and Epilepsy DVD”}, {“title”:“地球上的谁是汤姆贝克?”, salesRank“:{”Books“:3843450},”categories“:[['Books']]}, {”categories“:[['Clothing,Shoes&Jewelry','Girls'],['Clothing,Shoes &'Jewelry','Novelty,Costumes&More','Costumes&Accessories','More Accessories','Kids&Baby']],“description”:“description”,“title”:“Mog's Kittens”,“salesRank “:{”Books“:1760368}}}, {”description“:”三个Suess博士拼图“,”brand“:”Dr.Seuss“,”categories“:[['玩具和游戏','拼图','拼图']]}, – Nanan
对不起,很难读...但如果你看到字段”类别“,我会改变在双引号中使用单引号......但是在该字段中有不同数量的字符串 – Nanan