I'm trying to write a spec to do the below transformation using jolt transformation. I need to convert the flat JSON to nested JSON.
Input Data is almost same as this question.
I am having some trouble with converting the flat JSON to nested JSON. Here, i want to aggregate the data based on stoptype attribute. I use https://jolt-demo.appspot.com to test the following below.
Input Json:
[
{
"container_id": "ABC",
"shipperN": null,
"PNumber": null,
"trackingNumber": null,
"priority": null,
"loadNumber": "123345",
"billOfLading": "12345",
"addressLine1": "ABC Street",
"addressLine2": null,
"city": "Chicago",
"country": "US",
"latitude": null,
"longitude": null,
"earliestAppointmentTime": "XXXXX09:25",
"latestAppointmentTime": "XXXXX09:25",
"postalCode": "XXXXX3",
"sequence": "1",
"state": "XY",
"stopReferenceId": "0001",
"stopType": "PU",
"containerNumber": "XXXXXXXX"
},
{
"container_id": "ABC",
"shipperN": null,
"PNumber": null,
"trackingNumber": null,
"priority": null,
"loadNumber": "123345",
"billOfLading": "12345",
"addressLine1": null,
"addressLine2": null,
"city": null,
"country": null,
"latitude": null,
"longitude": null,
"earliestAppointmentTime": "XXXXX09:25",
"latestAppointmentTime": "XXXXX09:25",
"name": null,
"postalCode": null,
"sequence": "2",
"state": null,
"stopReferenceId": "XXXXD",
"stopType": "PL",
"containerNumber": "XXXXXXXX"
}
]
Expected Output:
[
{
"container_id": "ABC",
"shipperN": null,
"PNumber": null,
"trackingNumber": null,
"priority": null,
"loadNumber": "123345",
"billOfLading": "12345",
"PU":
{
"addressLine1": "ABC Street",
"city": "Chicago",
"country": "US",
"earliestAppointmentTime": "XXXXX09:25",
"latestAppointmentTime": "XXXXX09:25",
"postalCode": "XXXXX3",
"sequence": "1",
"state": "XY",
"stopReferenceId": "0001",
"stopType": "PU"
},
"PL" : {
"earliestAppointmentTime": "XXXXX09:25",
"latestAppointmentTime": "XXXXX09:25",
"sequence": "2",
"stopReferenceId": "dummy",
"stopType": "PL",
"externalAddressId": "dummy"
},
"containerNumber": "XXXXXXXX"
}
]
Here it is same jolt spec, i have used for last question. Link: Convert Flat json to Nested Json with multiple arrays and keep null values in output using Jolt transform

"null"(quoted) values, but"addressLine2" : "null"is still kept within the desired result ...