You can achieve this by a combination of default and shift operations.
First use a default to detect if itemName
is null and assign it a default value of true
Then use a shift to process the itemName
appropriately:
- if
itemName
is true
(i.e. was set in the default because its original value was null), then set isItemNameNull
using the value of itemName
- else copy
itemName
to the output (I've assumed that you want to do this, otherwise just leave this second bit out)
[
{
"operation": "default",
"spec": {
"itemName": true
}
},
{
"operation": "shift",
"spec": {
"*": "&",
"itemName": {
"true": {
"@1": "isItemNameNull"
},
"*": {
"@1": "itemName"
}
}
}
}
]
One caveat being that if the input has a string of "true"
for itemName
{
"itemName": "true",
"itemNumber": 22
}
then the output will be
{
"isItemNameNull": "true",
"itemNumber": 22
}
So not foolproof!
To get around that pitfall you could use a 3 step approach:
- if
itemName
is null assign it an appropriate default "marker" value
- process
itemName
and if it has the "marker" value set isItemNameNull
to String value "true"
- convert
isItemNameNull
to a boolean
[
{
"operation": "default",
"spec": {
"itemName": "null_marker"
}
},
{
"operation": "shift",
"spec": {
"*": "&",
"itemName": {
"null_marker": {
"#true" :"isItemNameNull"
},
"*": {
"@1": "itemName"
}
}
}
},
{
"operation": "modify-overwrite-beta",
"spec": {
"isItemNameNull": "=toBoolean"
}
}
]