【发布时间】:2021-01-25 00:55:30
【问题描述】:
我有这个 input.json
{
"list": [
{
"something1": "aaaa",
"status": {
"totalItems": 2,
"Items": [
{
"city": "santa",
"state": "VA",
"adress": "1 avenue"
},
{
"city": "manhatan",
"state": "NY",
"adress": "1 drive"
}
]
}
},
{
"something1": "bbbb",
"status": {
"totalItems": 0
}
}
]
}
我想添加列表并在值之间附加一些文本并输出如下:
{
"Newlist": [
{
"name": "NewName.aaaa",
"HaveItem": "Yes",
"Data": [
"santa is a city of VA with address 1 avenue",
"manhatan is a city of NY with address 1 drive"
]
},
{
"name": "NewName.bbbb",
"HaveItem": "No"
}
]
}
我尝试过使用 jq '.list | map({name: .something1, HaveItem: (if .status.totalItems != 0 then "Yes" else "No" end), Data: (if .status.totalItems != 0 then .status.Items else "NULL" end) })' 但我不知道如何在值之间添加字符串。
【问题讨论】:
标签: json string concatenation jq