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:
[
{
"container_id": "ABC_id",
"shipperN": null,
"PNumber": null,
"trackingNumber": null,
"loadNumber": "BO123345",
"billOfLading": "BO12345",
"addressLine1": "ABC Street",
"city": "ABC_city",
"country": "ABC_country",
"earliestAppointmentTime": "XXXXX09:25",
"postalCode": "XXXX3",
"sequence": "1",
"state": "ABC_state",
"stopReferenceId": "0001",
"stopType": "PU",
"containerNumber": "232323"
},
{
"container_id": "ABC_id",
"shipperN": null,
"PNumber": null,
"trackingNumber": null,
"loadNumber": "BO123345",
"billOfLading": "BO12345",
"addressLine1": null,
"city": "ABC1_city",
"country": "ABC1_country",
"earliestAppointmentTime": "XXXXX09:15",
"postalCode": "XXXX4",
"sequence": "2",
"state": "ABC1_state",
"stopReferenceId": "0002",
"stopType": "PL",
"containerNumber": "232323"
},
{
"container_id": "DEF_id",
"shipperN": null,
"PNumber": null,
"trackingNumber": null,
"loadNumber": "DO123345",
"billOfLading": "DO12345",
"addressLine1": null,
"city": "DEF_city",
"country": "DEF_country",
"earliestAppointmentTime": "XXXXX08:15",
"postalCode": "XXXX5",
"sequence": "4",
"state": "DEF_state",
"stopReferenceId": "0003",
"stopType": "PU",
"containerNumber": "454545"
},
{
"container_id": "DEF_id",
"shipperN": null,
"PNumber": null,
"trackingNumber": null,
"loadNumber": "DO123345",
"billOfLading": "DO12345",
"addressLine1": "DEF_address",
"city": "DEF1_city",
"country": "DEF_country",
"earliestAppointmentTime": "XXXXX07:15",
"postalCode": "XXXX6",
"sequence": "5",
"state": "DEF_state",
"stopReferenceId": "0004",
"stopType": "PL",
"containerNumber": "454545"
}
]
I am having some trouble with converting the flat JSON to nested JSON. Here, i want to aggregate the data based on stoptype attribute and need to be aggregated for unique payloads. I use https://jolt-demo.appspot.com to test the following below.
Output:
[
{
"container_id": "ABC_id",
"shipperN": null,
"PNumber": null,
"trackingNumber": null,
"loadNumber": "BO123345",
"billOfLading": "BO12345",
"PU": {
"addressLine1": "ABC Street",
"city": "ABC_city",
"country": "ABC_country",
"earliestAppointmentTime": "XXXXX09:25",
"postalCode": "XXXX3",
"sequence": "1",
"state": "ABC_state",
"stopReferenceId": "0001",
"stopType": "PU"
},
"PL": {
"addressLine1": null,
"city": "ABC1_city",
"country": "ABC1_country",
"earliestAppointmentTime": "XXXXX09:15",
"postalCode": "XXXX4",
"sequence": "2",
"state": "ABC1_state",
"stopReferenceId": "0002",
"stopType": "PL"
},
"containerNumber": "232323"
},
{
"container_id": "DEF_id",
"shipperN": null,
"PNumber": null,
"trackingNumber": null,
"loadNumber": "DO123345",
"billOfLading": "DO12345",
"PU": {
"addressLine1": null,
"city": "DEF_city",
"country": "DEF_country",
"earliestAppointmentTime": "XXXXX08:15",
"postalCode": "XXXX5",
"sequence": "4",
"state": "DEF_state",
"stopReferenceId": "0003",
"stopType": "PU"
},
"PL": {
"addressLine1": "DEF_address",
"city": "DEF1_city",
"country": "DEF1_country",
"earliestAppointmentTime": "XXXXX07:15",
"postalCode": "XXXX6",
"sequence": "5",
"state": "DEF_state",
"stopReferenceId": "0004",
"stopType": "PL"
},
"containerNumber": "454545"
}
]
can you please help me with this expected output.