I’m attempting to transform JSON to JSON by bringing the list values from the input JSON to the main object, but I’m finding the syntax confusing.
Input JSON:
[
{
"Request": {
"Id": "id1",
"name": "5-221734537593",
"CreatedBy": "abc",
"Updated": "02/28/2023 19:48:41",
"UpdatedBy": "xyz",
"ListOfNotes": {
"Notes": [
{
"sent": "Y",
"Id": "id2",
"Created": "02/28/2023 19:46:00",
"CreatedBy": "lmn",
"Updated": "02/28/2023 19:46:06",
"UpdatedBy": "efg"
},
{
"sent": "Y",
"Id": "id2",
"Created": "02/28/2023 19:46:00",
"CreatedBy": "lmn",
"Updated": "02/28/2023 19:46:06",
"UpdatedBy": "efg"
}
]
},
"ListOfActions": {
"Actions": [
{
"actId": "123",
"actionPerformed": "y",
"actionBy": "abc"
},
{
"actId": "234",
"actionPerformed": "y",
"actionBy": "xyz"
}
]
}
}
}
]
Expected output:
[
{
"Id": "id1",
"name": "5-221734537593",
"CreatedBy": "abc",
"Updated": "02/28/2023 19:48:41",
"UpdatedBy": "xyz"
},
{
"Notes": [
{
"sent": "Y",
"Id": "id2",
"Created": "02/28/2023 19:46:00",
"CreatedBy": "lmn",
"Updated": "02/28/2023 19:46:06",
"UpdatedBy": "efg"
},
{
"sent": "Y",
"Id": "id2",
"Created": "02/28/2023 19:46:00",
"CreatedBy": "lmn",
"Updated": "02/28/2023 19:46:06",
"UpdatedBy": "efg"
}
]
},
{
"Actions": [
{
"actId": "123",
"actionPerformed": "y",
"actionBy": "abc"
},
{
"actId": "234",
"actionPerformed": "y",
"actionBy": "xyz"
}
]
}
]
Spec tried:
[
{
"operation": "shift",
"spec": {
"*": {
"Request": {
"Id": "[#].&",
"name": "[#].&",
"CreatedBy": "[#].&",
"Updated": "[#].&",
"UpdatedBy": "[#].&"
}
}
}
}
]
The output I am currently getting is missing the Notes and Actions fields, and I am unsure how to correctly transform them.
[
{
"Id": "id1",
"name": "5-221734537593",
"CreatedBy": "abc",
"Updated": "02/28/2023 19:48:41",
"UpdatedBy": "xyz"
}
]
2
Answers
You can use the following shift transformation spec
If the order of input JSON is different, the following JOLT spec can be more accurate.