I have following json input and I need to get 2 additional attributes (head,foot) into the output json using existing Jolt. How I can do that?
JSONs and JOLT scripts are attached.
Input JSON:
[
{
"PropertyName": "KER ZONE 1",
"head": "13084",
"foot": "48b4e"
},
{
"Properties": [
{
"PropertyName": "KER ZONE 1",
"Property": [
{
"StartTime": "2023-04-03",
"Data": [
{
"GPSY": "45.28",
"GPSX": "-3.24",
"Val": "11.0",
"Metric": "mvw"
},
{
"GPSY": "45.28",
"GPSX": "-3.24",
"Val": "2231",
"Metric": "Hum"
},
{
"GPSY": "45.28",
"GPSX": "-3.24",
"Val": "0.00",
"Metric": "wat"
},
{
"GPSY": "45.28",
"GPSX": "-3.24",
"Val": "58.82",
"Metric": "temp"
},
{
"GPSY": "33.27",
"GPSX": "-4.29",
"Val": "0.00",
"Metric": "wat"
},
{
"GPSY": "33.27",
"GPSX": "-4.29",
"Val": "9.8",
"Metric": "mvw"
},
{
"GPSY": "33.27",
"GPSX": "-4.29",
"Val": "2206",
"Metric": "Hum"
},
{
"GPSY": "33.27",
"GPSX": "-4.29",
"Val": "58.28",
"Metric": "temp"
}
]
}
]
}
],
"CallStatus": "1"
}
]
Output JSON:
[
{
"Hum": "2231",
"Road_1": "SD",
"Road_2": "SF",
"Temp": 14.9,
"Temp_F": 58.82,
"Time": "2023-04-03",
"X": "-3.24",
"Y": "45.28",
"mvw": 11,
"head": "13084",
"foot": "48b4e"
},
{
"Hum": "2206",
"Road_1": "SD",
"Road_2": "SF",
"Temp": 14.6,
"Temp_F": 58.28,
"Time": "2023-04-03",
"X": "-4.29",
"Y": "33.27",
"mvw": 9.8,
"head": "13084",
"foot": "48b4e"
}
]
JOLT:
[
{
"operation": "shift",
"spec": {
"*": {
"*": {
"*": {
"*": {
"*": {
"*": {
"@2,StartTime": "@1,GPSY.@1,GPSX.Time",
"GPS*": "@(1,GPSY).@(1,GPSX).&",
"@Val": "@(1,GPSY).@(1,GPSX).@Metric"
}
}
}
}
}
}
}
},
{
"operation": "modify-overwrite-beta",
"spec": {
"*": {
"*": {
"Temp_C": "=doubleSum(@(1,temp),-32)",
"Temp": "=divideAndRound(3,@(1,Temp_C),1.8)",
"temp": "=toDouble",
"mvw": "=toDouble",
"hum": "=toInteger"
}
}
}
},
{ //Hard coded values
"operation": "default",
"spec": {
"*": {
"*": {
"Road_1": "SD",
"Road_2": "SF"
}
}
}
},
{
"operation": "shift",
"spec": {
"*": {
"*": {
"*": "&2.&3.&",
"GPSY": "&2.&3.Y",
"GPSX": "&2.&3.X",
"mvw": "&2.&3.mvw",
"hum": "&2.&3.Hum",
"temp": "&2.&3.Temp_F"
}
}
}
},
{
"operation": "cardinality",
"spec": {
"*": {
"*": {
"*": "ONE"
}
}
}
},
{
"operation": "shift",
"spec": {
"*": {
"*": "[]"
}
}
},
{
"operation": "remove",
"spec": {
"*": {
"wat": "",
"Temp_C": ""
}
}
}
]
Thank you
2
Answers
This Jolt spec will produce the desired output JSON with the head and foot attributes included.
You can use the following specs :