I am trying to convert the below JSON payload into a JSON that has the field name as the value of the field:
The jolt file that I have is working if field values are different. But if field values are the same then it is giving an array in the response.
Can you please help to provide jolt specifications for this?
Input JSON Payload:
{
"action": {
"Success": true,
"records": [
{
"Id": "Test_abc",
"SubscriptionID": "ID_1"
},
{
"Id": "Test_abc",
"SubscriptionID": "ID_2"
},
{
"Id": "Test_xyz",
"SubscriptionID": "ID_3"
}
],
"type": "update"
}
}
Expected output:
{
"action": {
"Success": true,
"records": {
"Test_abc": {
"SubscriptionID": "ID_1"
},
"Test_abc": {
"SubscriptionID": "ID_2"
},
"Test_xyz": {
"SubscriptionID": "ID_3"
}
},
"type": "update"
}
}
Solution not found yet.
2
Answers
You can use the following shift transformation spec
presumingly converting one of the
Id
value fromTest_abc
to another one such asTest_def
, since the desired output is wrong as a JSON value(There cannot be more than one object with the same tag at the same level)Your output is wrong. You can’t have multiple objects with the same keys.
If You want to support all objects of
records
array, You should bring them into an array like this spec:But, if you want to have an object as your
records
in the output, You should remove the duplicateID
like this spec: