In the attached JOLT, I want to change the date format, type conversion and string operation as follows.
- Date needs to change into yyyy-mm-dd hh:mm:ss format (2024-06-16 23:54:14) from UTC (2024-06-16T23:54:14.711456Z)
- The value of WEIGHT code needs to convert into decimal from string
- for machinename, needs to get only the name
Can someone please help on this. Thank you
Input JSON
{
"machine": "26619",
"mname": "MapRecord[{name=machine_col}]",
"timestamp": "2024-06-16T23:54:14.711456Z",
"temp": "16.0",
"height": "0.151",
"site": "2343",
"weight": "0.2955",
"length": "0.2"
}
JOLT:
[
{
"operation": "shift",
"spec": {
"mname": "machinename",
"timestamp": "Date",
"temp": {
"@": "data[0].value",
"#A2-P1-M1 5cm": "data[0].code"
},
"height": {
"@": "data[1].value",
"#A1-P1-T1 5cm": "data[1].code"
},
"weight": {
"@": "data[2].value",
"#WEIGHT": "data[2].code"
}
}
}
]
Output JSON:
{
"machinename" : "machine_col",
"Date" : "2024-06-16 23:54:14",
"data" : [ {
"value" : "16.0",
"code" : "A2-P1-M1 5cm"
}, {
"value" : "0.151",
"code" : "A1-P1-T1 5cm"
}, {
"value" : 0.2955,
"code" : "WEIGHT"
} ]
}
2
Answers
You can use the following transformation spec :
Hi I have modified your spec by adding few operations before it.
And Jolt currently don’t provide utility to change Date to required format but I have done it through modify-overwrite-beta by splitting with T and joining with empty space and also trimming the values till the length required in your date format.
Hope this helps!