我的数据提供者开始以两种不同的结构向我发送数据 (imageValue字段的差异:about组中的对象和banner组中的数组)
{
"valuesToUpload": [
{
"groupId": "about_2",
"groupTitle": "",
"fields": [
{
"fieldType": "image",
"valueId": "cd262467-e683-4b1a-8fff-b22c42722f2c",
"toUpload": true,
"imageValue": {
"imageId": 27606887612,
"imageSchema": "profile_composition",
"url": "http://img10/image/1/1.YaE0cFYle0oRLlTPlS7HAwtEINoMkYFRuB_k"
}
},
{
"fieldType": "image",
"fieldName": "example_images",
"valueId": "5b394732-28c1-424c-a5c8-5edd553a3711",
"toUpload": true,
"imageValue": {
"imageId": 27606306642,
"imageSchema": "profile_composition",
"url": "http://img40/image/1/1.j_RTsLassXjnkzZKMn-0czdeML_SxCdo-c"
}
},
{
"fieldType": "image",
"fieldName": "example_images",
"valueId": "efaeca0d-9dbe-4b1c-93a1-51cb54b9ec1b",
"toUpload": true,
"imageValue": {
"imageId": 27606343705,
"imageSchema": "profile_composition",
"url": "http://img00/image/1/1.xNLAhbas-l50pn65eZTqgqHrazl2.r39lMZMqeTovl4Cj2EY"
}
},
{
"groupId": "banner",
"groupTitle": "banner",
"fields": [
{
"fieldType": "image",
"imageValue": [
{
"imageId": 0000001,
"toUpload": true,
"valueId": "efaeca0d-9dbe-4b1c-93a1-51cb54b9ec00",
"imageSchema": "profile_composition",
"url": "https://20.img.st/image/1/link1"
},
{
"imageId": 0000002,
"toUpload": false,
"valueId": "efaeca0d-9dbe-4b1c-93a1-51cb54b9ec01",
"imageSchema": "profile_composition",
"url": "https://20.img.st/image/1/link2"
}
],
"fieldName": "banner",
"fieldTitle": "banner"
}
]
}]
}
],
"reload": {
"on": false
}
}
我需要“重新编译”横幅组图像字段,使其格式与 about_2 组中的格式相同
我发现了如何仅选择单独的对象格式(about_2):
{"valuesToUpload":[
.payload.valuesToUpload[]|{groupId,groupTitle,fields:[.fields[]| select(.valueId != null)]}
]}
仅获取“about_2”部分。
但是如何编写 jquery 将横幅部分重新编译为相同的格式而不丢失 about_2 部分。横幅部分必须类似于:
{
"groupId": "banner",
"groupTitle": "banner",
"fields": [
{
"fieldType": "image",
"valueId": "efaeca0d-9dbe-4b1c-93a1-51cb54b9ec00",
"toUpload": true,
"imageValue": {
"imageId": 0000001,
"imageSchema": "profile_composition",
"url": "https://20.img.st/image/1/link1"
}
},
{
"fieldType": "image",
"valueId": "efaeca0d-9dbe-4b1c-93a1-51cb54b9ec01",
"toUpload": true,
"imageValue": {
"imageId": 0000002,
"imageSchema": "profile_composition",
"url": "https://20.img.st/image/1/link2"
}
}
]
}
您只需将
.imageValue
中的值替换为其自己的项目即可将其相乘:.imageValue = .imageValue[]
。
要保留其余部分,请通过在 LHS 上向下遍历来更新相关部分,选择相关部分作为匹配
.groupId == "banner"
:
(.valuesToUpload[].fields[] | select(.groupId == "banner").fields[]) |= (
.imageValue = .imageValue[]
)