我正在尝试在给定的输出结构中获取下面给出的Input JSON,但我正在将结构作为List而不是Map。
输入结构:
{
"errorMessage": null,
"errorCode": null,
"state": "Complete",
"status": "Completed",
"createdDate": "234234234234",
"createdTime": "332432423433",
"orderId": {
"Order394": {
"orderId": "Order394",
"targetRequirements": [
{ "targetID" : "1234",
"targetDate" : "targetDate",
"preferenceOrder": 1,
"matchID": "502"
},
{ "targetID" : "1235",
"targetDate" : "targetDate",
"preferenceOrder": 1,
"matchID": "503"
}
],
"username": "Arun",
"address": "6166192",
"Title": "Kumar"
},
"Order395": {
"orderId": "Order395",
"targetRequirements": [
{ "targetDate" : "targetDate",
"targetID" : "1234",
"preferenceOrder": 1,
"matchID": "502"
}
],
"username": "Arun",
"address": "6166192",
"Title": "Kumar"
}
}
}
预期的响应:
{
"errorCode": null,
"errorMessage": null,
"orderId": {
"Order394": {
"orderId": "Order394",
"targetRequirements": [
{
"matchID": "502",
"preferenceOrder": 1
},
{
"matchID": "503",
"preferenceOrder": 1
}
]
},
"Order395": {
"orderId": "Order395",
"targetRequirements": [
{
"matchID": "502",
"preferenceOrder": 1
}
]
}
}
}
我尝试使用下面给出的JQ查询,但这正在创建orderId的LIST,但是我需要一张地图。
{ errorMessage,errorCode, orderId : (.orderId | map({ (.orderId) : { orderId , targetRequirements : (.targetRequirements | map({ preferenceOrder ,targetID }) ) } }) ) }
示例工作示例可在https://jqplay.org/s/exd2QjrS9V
中找到先谢谢了。 阿伦库马尔
答案 0 :(得分:1)
似乎您缺少对add
的调用。将add
添加到您的jq:
{ errorMessage,
errorCode,
orderId:
(.orderId
| map({ (.orderId) :
{ orderId,
targetRequirements:
(.targetRequirements
| map({preferenceOrder,targetID }) ) } })
| add ) }
这会产生所需的结构,但是输出在某些细节上与预期输出有所不同,因此您可能需要相应地调整过滤器。