Please help me to provide JOLT spec for the below input json. tried multiple approach but still not working
there is an condition check on risk attribute if risk is “0” then risklevel low .if it is “1” then High if it is null then it should be null only i got a solution for null value output json attibute is not showing.
[
{
"id": "12",
"name": "Manu",
"age": 26,
"location": "New York",
"risk": "0"
},
{
"id": "12",
"name": "Manju",
"age": 29,
"location": "New York",
"risk": null
},
{
"id": "123",
"name": "sanju",
"age": 24,
"location": "New York city",
"risk": "1"
},
{
"id": "1234",
"name": "Ramesh",
"age": 23,
"location": "India",
"risk": null
}
]
expected output json should looks like below.
[ {
"id": "12",
"location" : "New York",
"user":[{
"name" : "Manu",
"age" : 26,
"riskLevel" : "Low"
}, {
"name" : "Manju",
"age" : 29,
"riskLevel" : null
}]
},
{
"id": "123",
"location" : "New York city",
"user":[{
"name" : "sanju",
"age" : 24,
"riskLevel" : "High"
}]
},
{
"id": "123",
"location" : "India",
"user":[{
"name" : "Ramesh",
"age" : 23,
"riskLevel" : null
}]
}
]
Spec tried is below
[
{
"operation": "modify-overwrite-beta",
"spec": {
"*": {
"~risk": "NUll"
}
}
},
{
"operation": "shift",
"spec": {
"*": {
"id": "[&1].id",
"location": "[&1].location",
"name": "[&1].user[&1].name",
"age": "[&1].user[&1].age",
"risk": {
"0": { "#Low": "[&1].user[&1].riskLevel" },
"1": { "#High": "[&1].user[&1].riskLevel" },
"NUll": { "@": "[&1].user[&1].riskLevel" }
}
}
}
},
{
"operation": "shift",
"spec": {
"*": {
"id": "[&1].id",
"location": "[&1].location",
"user": "[&1].user"
}
}
}
]
New contributor
Manjunath k is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.