Is it possible to do more than one condition on a JOLT transformation to create or’s or and’s?
I found some documentation on If Else but haven’t been able to apply it to what I’m trying for. This is an if else on a single element, I need it with multiple or’s. For instance I have the following json:
[
{
"alpha": "a",
"beta": "b",
"omega": "o",
"exists": true,
"description": "goodbye world"
},
{
"alpha": "1",
"beta": "2",
"omega": "3",
"exists": false,
"description": "hello world"
},
{
"alpha": "z",
"beta": "x",
"omega": "y",
"exists": true,
"description": "hello mars"
}
]
I need to figure out a JOLT that can look at the entire array and say "if Exists is True or description is hello world" So it outputs:
[
{
"alpha": "a",
"beta": "b",
"omega": "o",
"exists": true,
"description": "goodbye world"
},
{
"alpha": "1",
"beta": "2",
"omega": "3",
"exists": false,
"description": "hello world"
},
{
"alpha": "z",
"beta": "x",
"omega": "y",
"exists": true,
"description": "hello mars"
}
]
Jolt to find hello world:
[
{
"operation": "shift",
"spec": {
"*": {
"description": {
"hello world": null,
"*": {
"@2": "&1"
}
}
}
}
}
]
I know how jolt for for the if exists and the filter or description piece but how do I put them together to work in unison like an or clause such as:
if(("exists" == "true") | ("description" == "hello world"))
2
Answers
You can generate a new attribute by concatenating those values(
true
andhello world
), and then check out for the existence by your conditional checking method such asWhat do you think of the below solution which I seem to make it work with one shift unless I’m missing something.
Thanks.