【发布时间】:2021-10-15 15:33:11
【问题描述】:
我有一个 JSON 字符串作为单行文件,元素之间没有空格。这就是 JSON 的样子。
{"data":[{"ids":[{"index":"01","type":"02","id":"XYZ12345"}],"scores":[{"name":"STKOVERFLOW","cardName":"08","cardVersion":"10","date":"10062019","score":"00730","reasons":[{"code":"X2345","value":"01"}]}],"telephones":[{"index":"01","number":"9841234567","extension":"4424386","type":"01"}]}]}
我必须从 JSON 树中删除分数数组。
我的想法是先删除reasons数组,然后删除scores数组
我尝试了几种方法,但它不起作用。任何帮助表示赞赏。
sed 's/\,\"reasons.*\]//' < input.json #This removes "]" till the last array present in the json.
sed 's/\,\"reasons.*?\]//' < input.json #This does not remove any characters in the input
sed 's/\,\"reasons(.*?)\]//' < input.json #This does not remove any characters in the input
我想使用 sed 来实现这一点,因为组织中现在没有其他工具。
感谢您的帮助。谢谢!!
【问题讨论】: