我有一个很长的JSON列表,我想在它上添加前缀,但是有困难的时候,无论如何,如何使用任何工具,如崇高,在线或javascript?
这是我的示例json,前缀是这个json执行后的文件名,所以我需要添加underscore
。就像下面一样。
在它成为"prefix": "Z99438",
之前,它将成为"prefix": "Z99438_",
{
"Records": [
{
"prefix": "Z99438_",
"keywords": "Lancome Nutrix Nourishing and Repairing Treatment Rich Cream 75ml",
"limit": 1,
"print_urls": true,
"image_directory": "A002152"
},
{
"prefix": "Z99438_",
"keywords": "Tom Ford Black Orchid Eau de Parfum 50ml Spray",
"limit": 1,
"print_urls": true,
"image_directory": "A00586"
}
]
...
}
也知道如何用相同的键和值添加新属性吗?
发布于 2018-10-19 07:12:57
有工具吗?下面是一些使用jq
命令行解析器的示例。
如果要将_
附加到所有prefix
jq '.Records[].prefix |= . + "_"' file
如果要将_
附加到只有值为Z99438
的prefix
中
jq '.Records |= map(select(.prefix == "Z99438").prefix |= . + "_")' file
https://stackoverflow.com/questions/52895004
复制