I have the following input JSON value :
{
"A": {
"B": [
{
"tempName": "rq3ewas",
"name": "test1"
},
{
"tempName": "",
"name": "test2"
},
{
"tempName": null,
"name": "test3"
},
{
"tempName": "test4"
}
]
}
}
and want to get the following output based on ;
scenario1: If "tempname"
is not null, then set the value of "name"
to "tempName"
.
scenario2: If "tempname"
is null, then keep the default value of "name"
without changing it.
scenario3: If "tempname"
is empty string(""
), then keep the default value of "name"
without changing it
scenario4: But If "tempname"
is not present, then keep the default value of "name"
Except first scenario, last three are not working. If the code is modified last three works and first scenario is getting failed.
[
{
"operation": "modify-overwrite-beta",
"spec": {
"A": {
"B": {
"*": {
"name": "=firstNotNull(@(1,tempName), @(2,name))"
}
}
}
}
},
{
"operation": "remove",
"spec": {
"A": {
"B": {
"*": {
"tempName": ""
}
}
}
}
}
]
O/p:
{
"A" : {
"B" : [ {
"name" : "rq3ewas"
}, {
"name" : null
}, {
"name" : ""
}, {
"name" : "test4"
} ]
}
}
Expected O/p:
{
"A" : {
"B" : [ {
"name" : "rq3ewas"
}, {
"name" : "test2"
}, {
"name" : "test3"
}, {
"name" : "test4"
} ]
}
}
[
{
"operation": "modify-overwrite-beta",
"spec": {
"A": {
"B": {
"*": {
"name": "=firstNotNull(@(1,tempName), @(2,name))"
}
}
}
}
},
{
"operation": "remove",
"spec": {
"A": {
"B": {
"*": {
"tempName": ""
}
}
}
}
}
]
2
Answers
Thank you, This is working. Facing issue with one more spec similar for converting JSON to Array.
Input JSON:
spec applied:
O/p:
Expected output:
Principally you should get rid of the empty string, since manipulating null valued attributes is possible with modify specs. Having aimed this, the following transformation might be used :