I have an input json in the form of key, value pair.
I don’t want to include the key in the output if value for that key is missing. As in this input
teacherid is missing, so it shouldn’t be included in the ouput.
input :
{
"alldetails": {
"classid": 1,
"schoolid": 3
}
}
jolt spec :
[
{
"operation": "shift",
"spec": {
"alldetails": {
"#Id_class": "data[0].source",
"classid": "data[0].value",
"#Id_teacher": "data[1].source",
"teacherid": "data[1].value",
"#Id_school": "data[2].source",
"schoolid": "data[2].value"
}
}
}
]
current output :
{
"data": [
{
"source": "Id_class",
"value": 1
},
{
"source": "Id_teacher"
},
{
"source": "Id_school",
"value": 3
}
]
}
desired output :
{
"data": [
{
"source": "Id_class",
"value": 1
},
{
"source": "Id_school",
"value": 3
}
]
}
Any help would be appreciated. Thanks
2
Answers
This worked for me
No need to hardcode but a shift transformation in the following case will handle the issue without prefixing the values with
Id_
, and to do this apply a modify-overwrite transformation such asthe input already is not got to do with
teacher
the demo on the site http://jolt-demo.appspot.com/ is :
Edit : Based on your need, you might construct the transformation starting from an input which’s preety similar to yours such as