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 but for null value output json attribute is not showing.
Input JSON :
[
{
"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 JSON :
[
{
"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
}
]
}
]
2
Answers
You can use the following transformation
Thanks Barbaros for the awesome solution. I’m always learning form you and getting better in jolt because of your solutions. I would never knew that "~" has special meaning in jolt. May I ask how did you find out about it? is there url that you use for jolt guide that is comprehensive and has the latest?
Also if I may provide a different way for the spec:
Also since I have been experiencing with jslt , I would like to provide a much abbreviated way of solving this using jstl: