我正在尝试将该键移动到另一个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"
}
}
}
}
我期望的输出是这样的:
案例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"
}
}
}
}
有没有可能修改我目前的震动规格,以涵盖上述两种情况?