Reputation: 23
I have three scenario which are:
Scenario 1: When "testInt" == 10
then "isTrue"
should be set to false
and "testInt"
to 0
and "testString"
as it is.
Input
{
"testString" :"testValue",
"testInt": 10,
"isTrue": true
}
Expected output
{
"testString" :"testValue",
"testInt": 0,
"isTrue": false
}
Scenario 2: When "testInt" == null
then "testInt"
should be removed and others as it is.
Input
{
"testString" :"testValue",
"testInt": null,
"isTrue": true
}
Expected output
{
"testString" :"testValue",
"isTrue": true
}
Scenario 3: When "testInt" != 10
(also not null
) then no changes.
Input
{
"testString" :"testValue",
"testInt": 20,
"isTrue": true
}
Expected output
{
"testString" :"testValue",
"testInt": 20,
"isTrue": true
}
It will be helpful if someone suggest me how to achieve these through jolt shift operation.
Upvotes: 1
Views: 1829
Reputation: 65323
You can define such a shift
operation along with default
operation in order to be able to handle null
cases through "null"
to null
conversion
[{
"operation": "default",
"spec": {
"testInt": "null"
}
},{
"operation": "shift",
"spec": {
"testString": "testString",
"testInt": {
"10": {
"#0": "testInt"
},
"null": null,
"*": {
"@(2,testInt)": "testInt"
}
},
"isTrue": {
"@(2,testInt)": {
"10": {
"#false": "isTrue"
},
"*": {
"@(3,isTrue)": "isTrue"
}
}
}
}
}]
where @(integer,key)
such as "@(2,testInt)"
or "@(3,isTrue)"
representing the level going up to start search for the needed key presented as the second argument. That can be calculated by counting opening curly braces after "spec": {
except for this first {
within "spec": {
.
Upvotes: 1