我正在try 将密钥移动到另一个JSON密钥的值.目标值是一个数组,我正在try 向该数组添加一个元素.
case 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"
}
}
}
}
case 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"
} ]
}
case 2预期yields :
{
"Name" : {
"PRI" : {
"firstName" : "Joe"
}
},
"Ids" : [ {//from OtherIds
"country" : "USA", // hard-coding this
"IdType" : "SSN Tail", //hard-coding this
"idLast" : "2023"
} ]
}
我目前的震荡规格:
[
{
"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"
}
}
}
}
是否可以修改我目前的Jolt规格,以涵盖上述两种情况?