我试图将键移动到另一个JSON键的值。目标值是一个数组,我试图向该数组添加一个元素。
用例1:输入json对象:
{
"Name": {
"PRI": {
"firstName": "Joe"
}
},
"Ids": {
"IND": {
"IND-ADR": {
"id": "ind-adr-id",
"key": "ind1"
},
"IND-PAN": {
"id": "ind-pan-id",
"key": "ind2"
}
},
"USA": {
"USA-SSN": {
"id": "usa-ssn-id",
"key": "usa1"
}
}
},
"OtherIds": {
"1970-01-01": {
"0": {
"idLast": "2023"
}
}
}
}
字符串
用例2:输入json对象:
{
"Name": {
"PRI": {
"firstName": "Joe"
}
},
"OtherIds": {
"1970-01-01": {
"0": {
"idLast": "2023"
}
}
}
}
型
我期望的输出是这样的:Case 1期望的输出:
{
"Name" : {
"PRI" : {
"firstName" : "Joe"
}
},
"Ids" : [ {
"country" : "IND",
"IdType" : "IND-ADR",
"id" : "ind-adr-id",
"key" : "ind1"
}, {
"country" : "IND",
"IdType" : "IND-PAN",
"id" : "ind-pan-id",
"key" : "ind2"
}, {
"country" : "USA",
"IdType" : "USA-SSN",
"id" : "usa-ssn-id",
"key" : "usa1"
}, { //from OtherIds
"country" : "USA", // hard-coding this
"IdType" : "SSN Tail", //hard-coding this
"idLast" : "2023"
} ]
}
型
案例2预期输出:
{
"Name" : {
"PRI" : {
"firstName" : "Joe"
}
},
"Ids" : [ {//from OtherIds
"country" : "USA", // hard-coding this
"IdType" : "SSN Tail", //hard-coding this
"idLast" : "2023"
} ]
}
型
我目前的Jolt规格:
[
{
"operation": "shift",
"spec": {
"Ids": {
"*": {
"*": {
"$1": "NID.&2_&1.&3.country",
"$": "NID.&2_&1.&3.IdType",
"*": "NID.&2_&1.&3.&"
}
}
},
"*": "&"
}
},
{
"operation": "shift",
"spec": {
"NID": {
"*": {
"*": {
"*": "&1[#3].&"
}
}
},
"*": "&"
}
}
]
型
我的当前输出:
{
"Name" : {
"PRI" : {
"firstName" : "Joe"
}
},
"Ids" : [ {
"country" : "IND",
"IdType" : "IND-ADR",
"id" : "ind-adr-id",
"key" : "ind1"
}, {
"country" : "IND",
"IdType" : "IND-PAN",
"id" : "ind-pan-id",
"key" : "ind2"
}, {
"country" : "USA",
"IdType" : "USA-SSN",
"id" : "usa-ssn-id",
"key" : "usa1"
} ],
"OtherIds" : {
"1970-01-01" : {
"0" : {
"idLast" : "2023"
}
}
}
}
型
是否有可能修改我目前的震动规格,以涵盖上述两种情况?
1条答案
按热度按时间pwuypxnk1#
您可以在第一个规范中分别选择键为
"Ids"
和"OtherIds"
的对象,同时提取要在第二个规范中使用的文字"Ids"
,第二个规范将在左手侧包含**#
**运算符,以硬编码所需的文字,例如字符串
这是两个输入的公共变换。