Convert the flat json to nested json for the multiple payloads. I am having some trouble with converting the flat JSON to nested JSON. Here, i want to aggregate the data to stops and need to be aggregated for unique payloads. I use https://jolt-demo.appspot.com to test the following below.
input:
[
{
"container_id": "DEF_id",
"haulType": "OL",
"loadNumber": "DO123345",
"billOfLading": "DO12345",
"referenceNumbers": "LoadIDEF",
"addressLine1": "DEF_address",
"stopReferenceId": "0004",
"stopType": "PL",
"containerNumber": "454545"
},
{
"container_id": "DEF_id",
"haulType": "OL",
"loadNumber": "DO123345",
"billOfLading": "DO12345",
"referenceNumbers": "LoadIDEF",
"addressLine1": null,
"stopReferenceId": "0003",
"stopType": "PU",
"containerNumber": "454545"
},
{
"container_id": "ABC_id",
"haulType": "IL",
"loadNumber": "BO123345",
"billOfLading": "BO12345",
"referenceNumbers": "LoadID",
"addressLine1": null,
"stopReferenceId": "0002",
"stopType": "PL",
"containerNumber": "232323"
},
{
"container_id": "ABC_id",
"haulType": "IL",
"loadNumber": "BO123345",
"billOfLading": "BO12345",
"referenceNumbers": "LoadID",
"addressLine1": "ABC Street",
"stopReferenceId": "0001",
"stopType": "PU",
"containerNumber": "232323"
}
]
Expected Output:
[
{
"load": {
"container_id": "DEF_id",
"haulType": [
"OL"
],
"loadNumber": "DO123345",
"billOfLading": "DO12345",
"referenceNumbers": [
"LoadIDEF"
],
"stops": [
{
"addressLine1": "DEF_address",
"stopReferenceId": "0004",
"stopType": "PL"
},
{
"addressLine1": null,
"stopReferenceId": "0003",
"stopType": "PU"
}
]
},
"containerInfo": {
"containerNumber": "454545"
}
},
{
"load": {
"container_id": "ABC_id",
"haulType": [
"IL"
],
"loadNumber": "BO123345",
"billOfLading": "BO12345",
"referenceNumbers": [
"LoadID"
],
"stops": [
{
"addressLine1": null,
"stopReferenceId": "0002",
"stopType": "PL"
},
{
"addressLine1": "ABC Street",
"stopReferenceId": "0001",
"stopType": "PU"
}
]
},
"containerInfo": {
"containerNumber": "232323"
}
}
]
Here it is my jolt spec used
[
{
"operation": "shift",
"spec": {
"*": {
"container_id": "@(1,containerNumber).load.&",
"haulType": "@(1,containerNumber).load.&",
"loadNumber": "@(1,containerNumber).load.&",
"billOfLading": "@(1,containerNumber).load.&",
"referenceNumbers": "@(1,containerNumber).load.&",
"addressLine1": "@(1,containerNumber).load.stops[&1].&",
"stopReferenceId": "@(1,containerNumber).load.stops[&1].&",
"stopType": "@(1,containerNumber).load.stops[&1].&",
"containerNumber": "@(1,containerNumber).containerInfo.&"
}
}
},
{
"operation": "cardinality",
"spec": {
"*": {
"*": {
"*": "ONE",
"stops": "MANY"
}
}
}
},
{
"operation": "shift",
"spec": {
"*": {
"*": "&",
"load": {
"haulType|referenceNumbers": "&1.&[]",
"*": "&1.&"
}
}
}
}
]
