I m having difficulty in writing a jolt spec for different JSON inputs. I need to get a generic jolt spec so that i get a flattened json
Input 1 :
[
{
"OrderInfo": [
{
"OrderHeader": {
"orderType": "PULL",
"customerPOType": "",
"enteredDate": "20220324190249",
"mitSect": "",
"mitBillingFacility": "",
"customerCode": "Z177",
"mitAccNo": "",
"userCWSId": "ANDERM2",
"userName": "Michael Andersen",
"rushFlag": 0,
"customerPONumber": "",
"mitPriorityIndicator": "",
"mitOrderNumber": "",
"customerFacilityCode": "JA",
"GSIOrderNumber": "SHIVAM1000000100",
"dtCode": "JADOJA",
"mitRemarks": ""
},
"OrderDetails": [
{
"deliverToCoordinates": " SUPRA2RA",
"exactQuantityFlag": "",
"earlyShipDate": "20220324190249",
"deliverToDockBuilding": "JA",
"preferredWarehouseId": "SE92",
"deliverToBuilding": "A2",
"deliverToDropZoneArea": " A2A",
"orderQuantity": 100,
"orderMethod": "P",
"plannedFirmIndicator": "F",
"transactionType": "A",
"lateShipDate": "",
"crossdockFlag": 0,
"deliverToArea": " A2A",
"partNumber": "2T3001",
"buildSequenceNumber": "",
"deliverToDropZoneBuilding": "A2",
"orderLineNumber": 1,
"deliverToDockArea": "DOJA"
}
]
},
{
"OrderHeader": {
"orderType": "PULL",
"customerPOType": "",
"enteredDate": "20220324190249",
"mitSect": "",
"mitBillingFacility": "",
"customerCode": "Z177",
"mitAccNo": "",
"userCWSId": "ANDERM2",
"userName": "Michael Andersen",
"rushFlag": 0,
"customerPONumber": "",
"mitPriorityIndicator": "",
"mitOrderNumber": "",
"customerFacilityCode": "JA",
"GSIOrderNumber": "SHIVAM1000000100",
"dtCode": "JADOJA",
"mitRemarks": ""
},
"OrderDetails": [
{
"deliverToCoordinates": " SUPRA2RA",
"exactQuantityFlag": "",
"earlyShipDate": "20220324190249",
"deliverToDockBuilding": "JA",
"preferredWarehouseId": "SE92",
"deliverToBuilding": "A2",
"deliverToDropZoneArea": " A2A",
"orderQuantity": 100,
"orderMethod": "P",
"plannedFirmIndicator": "F",
"transactionType": "A",
"lateShipDate": "",
"crossdockFlag": 0,
"deliverToArea": " A2A",
"partNumber": "2T3001",
"buildSequenceNumber": "",
"deliverToDropZoneBuilding": "A2",
"orderLineNumber": 1,
"deliverToDockArea": "DOJA"
}
]
}
]
}
]
Input 2 :
[
{
"OrderInfo": [
{
"OrderHeader": {
"orderType": "MCOE",
"esoNumber": "TLVKK00",
"rushFlag": "0",
"serialNumber": "CA900319",
"enteredDate": "20220110082146",
"customerFacilityCode": "LE",
"GSIOrderNumber": "DS0000000055068",
"customerCode": "Z319"
},
"OrderDetails": [
{
"deliverToCoordinates": "S-X=ILCMC ",
"exactQuantityFlag": "Y",
"earlyShipDate": "20220110082146",
"deliverToDockBuilding": "LE",
"kanbanNumber": "SAMG 047877",
"preferredWarehouseId": "",
"deliverToBuilding": "B",
"buildDate": "20211208000000",
"deliverToDropZoneArea": "04M",
"orderQuantity": 8,
"startOnLineDate": "20211207000000",
"warehouseId": "",
"crossdockFlag": 0,
"deliverToArea": "04M",
"partNumber": "7K1181",
"buildSequenceNumber": "012",
"deliverToDropZoneBuilding": "B ",
"orderLineNumber": 90,
"deliverToDockArea": "DOCK"
},
{
"deliverToCoordinates": "S-X=ILCMC ",
"exactQuantityFlag": "Y",
"earlyShipDate": "20220110082146",
"deliverToDockBuilding": "LE",
"kanbanNumber": "SAMG 020472",
"preferredWarehouseId": "",
"deliverToBuilding": "B",
"buildDate": "20211208000000",
"deliverToDropZoneArea": "04M",
"orderQuantity": 4,
"startOnLineDate": "20211207000000",
"warehouseId": "",
"crossdockFlag": 0,
"deliverToArea": "04M",
"partNumber": "6V8398",
"buildSequenceNumber": "012",
"deliverToDropZoneBuilding": "B ",
"orderLineNumber": 173,
"deliverToDockArea": "DOCK"
}
]
}
]
}
]
JSON Ouput Required -
Single Flattened JSON :
[
{
"GSIOrderNumber": "SHIVAM1000000100",
"Orderdetails.deliverToCoordinates": " SUPRA2RA",
"Orderdetails.exactQuantityFlag": "",
"Orderdetails.earlyShipDate": "20220324190249",
"Orderdetails.deliverToDockBuilding": "JA",
"Orderdetails.preferredWarehouseId": "SE92",
"Orderdetails.deliverToBuilding": "A2",
"Orderdetails.deliverToDropZoneArea": " A2A",
"Orderdetails.orderQuantity": 100,
"Orderdetails.orderMethod": "P",
"Orderdetails.plannedFirmIndicator": "F",
"Orderdetails.transactionType": "A",
"Orderdetails.lateShipDate": "",
"Orderdetails.crossdockFlag": 0,
"Orderdetails.deliverToArea": " A2A",
"Orderdetails.partNumber": "2T3001",
"Orderdetails.buildSequenceNumber": "",
"Orderdetails.deliverToDropZoneBuilding": "A2",
"Orderdetails.orderLineNumber": 1,
"Orderdetails.deliverToDockArea": "DOJA"
}
]
Jolt Spec i Tried is working for Input 2 but not for Input 1 :
[
{
"operation": "shift",
"spec": {
"*": {
"OrderInfo": {
"*": {
"OrderDetails": {
"*": {
"@(2,OrderHeader.GSIOrderNumber)": "[&].GSIOrderNumber",
"*": "[&1].Orderdetails\\.&"
}
}
}
}
}
}
}
]
Pls help I m having difficulty in writing a jolt spec for different JSON inputs. I need to get a generic jolt spec so that i get a flattened json
CodePudding user response:
The following shift transformation specs would produce the desired outputs per each of the input
[
{
"operation": "shift",
"spec": {
"*": {
"OrderInfo": {
"*": {
"OrderDetails": {
"*": {
"@(2,OrderHeader.GSIOrderNumber)": "[&3].&1.GSIOrderNumber",
"*": "[&3].&1.&"
}
}
}
}
}
}
},
{
"operation": "shift",
"spec": {
"*": {
"*": ""
}
}
}
]
where one more layer to be added(by using &1
), and seperate the objects at a higher level(by using [&3]
), then get rid of the objects keys within the last spec.