bazaarvoice / jolt

JSON to JSON transformation library written in Java.
Apache License 2.0
1.56k stars 329 forks source link

After using shift I'm trying to handle null values of attribute not exists but default not working properly #1147

Open mukesh0801 opened 2 years ago

mukesh0801 commented 2 years ago

Input:

{ "reference": "23548794502", "payloadType": "Mawb", "payload": { "type": "flight status", "id": "7675bd62-2ca8-4172-8cf0-fed7eb4cf7d9", "airWaybillNumber": "23548794502", "originAndDestination": { "origin": "SGN", "destination": "ORD" }, "quantity": { "shipmentDescriptionCode": "TOTAL_CONSIGNMENT", "numberOfPieces": 34, "weight": { "amount": 4818, "unit": "KILOGRAM" } }, "totalNumberOfPieces": 34, "events": [ { "type": "departed", "numberOfPieces": 34, "weight": { "amount": 4818, "unit": "KILOGRAM" }, "timeOfEvent": "2022-06-08T03:57:09", "timeOfEventTimePartQuality": "SUPPLIED", "flight": "TK62ss75", "ecefLongitude": 0.123, "ecefLatitude": 0.22, "origin": "IST", "destination": "ORD", "estimatedTimeOfDeparture": "2022-06-07T20:35:00", "estimatedTimeOfArrival": "2022-06-08T00:05:00" }, { "type": "received from carrier", "numberOfPieces": 34, "weight": { "amount": 4818, "unit": "KILOGRAM" }, "timeOfEvent": "2022-06-08T03:57:09", "timeOfEventTimePartQuality": "SUPPLIED", "flight": "TK62ss75", "ecefLongitude": 0.123, "ecefLatitude": 0.22, "origin": "IST", "destination": "ORD", "estimatedTimeOfDeparture": "2022-06-07T20:35:00", "estimatedTimeOfArrival": "2022-06-08T00:05:00" } ] } }

Spec: [

{ "operation": "shift", "spec": { "payload": { "events": { "": { "#PROCESS_AIR_UPDATE": "transformedPayload.[&1].MessageType", "#YourEDI": "transformedPayload.[&1].Source", "@(3,reference)": ["transformedPayload.[&1].Content.AirDataHash.load_number", "transformedPayload.[&1].Content.DataHash.bill_of_lading"], "@(2)": { "quantity": { "numberOfPieces": "transformedPayload.[&3].Content.AirDataHash.quantity" } }, "timeZone": { "null": { "#LT": ["transformedPayload.[&3].Content.AirDataHash.event_timezone_code", "transformedPayload.[&3].Content.DataHash.event_timezone"] }, "": { "@(2,timeZone)": ["transformedPayload.[&3].Content.AirDataHash.event_timezone_code", "transformedPayload.[&3].Content.DataHash.event_timezone"] } }, "timeOfEvent": ["transformedPayload.[&1].Content.DataHash.event_date_time", "transformedPayload.[&1].Content.AirDataHash.events[0].event_time"], "estimatedTimeOfArrival": "transformedPayload.[&1].Content.AirDataHash.events[0].eta", "location": { "lattitude": "transformedPayload.[&2].Content.AirDataHash.events[0].latitude", "longitude": "transformedPayload.[&2].Content.AirDataHash.events[0].longitude" }, "type": { "arrived": { "#X4": "transformedPayload.[&3].Content.AirDataHash.events[0].status_code", "@(2,destination)": ["transformedPayload.[&3].Content.DataHash.ms1_city", "transformedPayload.[&3].Content.AirDataHash.events[0].city"] }, "departed": { "#P1": "transformedPayload.[&3].Content.AirDataHash.events[0].status_code", "@(2,origin)": ["transformedPayload.[&3].Content.DataHash.ms1_city", "transformedPayload.[&3].Content.AirDataHash.events[0].city"] }, "booked": { "#BF": "transformedPayload.[&3].Content.AirDataHash.events[0].status_code" }, "received from shipper": { "#I1": "transformedPayload.[&3].Content.AirDataHash.events[0].status_code" }, "received from flight": { "#UC": "transformedPayload.[&3].Content.AirDataHash.events[0].status_code" }, "consignee notified": { "#AV": "transformedPayload.[&3].Content.AirDataHash.events[0].status_code" }, "delivered": { "#D1": "transformedPayload.[&3].Content.AirDataHash.events[0].status_code" }, "manifested": { "#L1": "transformedPayload.[&3].Content.AirDataHash.events[0].status_code" }, "freight prepared": { "#CP": "transformedPayload.[&3].Content.AirDataHash.events[0].status_code" }, "freight on hand": { "#I1": "transformedPayload.[&3].Content.AirDataHash.events[0].status_code" }, "arrival documentation delivered": { "#OO": "transformedPayload.[&3].Content.AirDataHash.events[0].status_code" }, "arrival documentation received": { "#OO": "transformedPayload.[&3].Content.AirDataHash.events[0].status_code" }, "received from carrier": { "#R1": "transformedPayload.[&3].Content.AirDataHash.events[0].status_code" }, "transferred to carrier": { "#AN": "transformedPayload.[&3].Content.AirDataHash.events[0].status_code" }, "customs cleared": { "#CT": "transformedPayload.[&3].Content.AirDataHash.events[0].status_code" }, "reported to customs": { "#K1": "transformedPayload.[&3].Content.AirDataHash.events[0].status_code" }, "in flight": { "#X6": "transformedPayload.[&3].Content.AirDataHash.events[0].status_code" }, "": { "@(2,type)": "transformedPayload.[&3].Content.AirDataHash.events[0].status_code" } }, "flight": { "#AF": "transformedPayload.[&2].Content.DataHash.reference_numbers[0].type", "@(1,flight)": "transformedPayload.[&2].Content.DataHash.reference_numbers[0].value" } } } } } }, { "operation": "modify-overwrite-beta", "spec": { "transformedPayload": { "": { "Content": { "DataHash": { "events": { "event_timezone": "=toString", "*": { "latitude": "=toString", "longitude": "=toString" } } } } } } } }, { "operation": "default", "spec": { "transformed": [{ "Content": { "DataHash": { "event_timezone": "PT" } } }], "metaData": { "domain": "Air", "eventType": "airMilestoneUpdate", "version": "v1", "(@1,flight)": "lll" } } } ]

Output:

{ "transformedPayload" : [ { "MessageType" : "PROCESS_AIR_UPDATE", "Source" : "YourEDI", "Content" : { "AirDataHash" : { "load_number" : "23548794502", "quantity" : 34, "events" : [ { "event_time" : "2022-06-08T03:57:09", "eta" : "2022-06-08T00:05:00", "status_code" : "P1", "city" : "IST" } ] }, "DataHash" : { "bill_of_lading" : "23548794502", "event_date_time" : "2022-06-08T03:57:09", "ms1_city" : "IST", "reference_numbers" : [ { "type" : "AF", "value" : "TK62ss75" } ], "events" : { } } } }, { "MessageType" : "PROCESS_AIR_UPDATE", "Source" : "YourEDI", "Content" : { "AirDataHash" : { "load_number" : "23548794502", "quantity" : 34, "events" : [ { "event_time" : "2022-06-08T03:57:09", "eta" : "2022-06-08T00:05:00", "status_code" : "R1" } ] }, "DataHash" : { "bill_of_lading" : "23548794502", "event_date_time" : "2022-06-08T03:57:09", "reference_numbers" : [ { "type" : "AF", "value" : "TK62ss75" } ], "events" : { } } } } ], "metaData" : { "domain" : "Air", "eventType" : "airMilestoneUpdate", "version" : "v1", "(@1,flight)" : "lll" }, "transformed" : [ { "Content" : { "DataHash" : { "event_timezone" : "PT" } } } ] }

Output I want:

{ "transformedPayload" : [ { "MessageType" : "PROCESS_AIR_UPDATE", "Source" : "YourEDI", "Content" : { "AirDataHash" : { "load_number" : "23548794502", "quantity" : 34, "events" : [ { "event_time" : "2022-06-08T03:57:09", "eta" : "2022-06-08T00:05:00", "status_code" : "P1", "city" : "IST" } ] }, "DataHash" : { "bill_of_lading" : "23548794502", "event_date_time" : "2022-06-08T03:57:09", "ms1_city" : "IST", "reference_numbers" : [ { "type" : "AF", "value" : "TK62ss75" } ], "events" : { } } } }, { "MessageType" : "PROCESS_AIR_UPDATE", "Source" : "YourEDI", "Content" : { "AirDataHash" : { "load_number" : "23548794502", "event_timezone": "LT", "quantity" : 34, "events" : [ { "event_time" : "2022-06-08T03:57:09", "eta" : "2022-06-08T00:05:00", "status_code" : "R1" } ] }, "DataHash" : { "bill_of_lading" : "23548794502", "event_date_time" : "2022-06-08T03:57:09", "reference_numbers" : [ { "type" : "AF", "value" : "TK62ss75" } ], "events" : { } } } } ], "metaData" : { "domain" : "Air", "eventType" : "airMilestoneUpdate", "version" : "v1", "(@1,flight)" : "lll" }, "transformed" : [ { "Content" : { "DataHash" : { "event_timezone" : "PT" } } } ] }

Eventtimezone is not coming pls check