cancel
Showing results for 
Search instead for 
Did you mean: 

Conditionally Remove or Add a Field

Ish
New Contributor III

Hello,

How do you conditionally remove (or add) a field to a document?

E.g., I have a mapper:

Expression → Target Path
20 → $field1
10 → $field2
‘’ → $field3
null → $field4

So I now have:
[
{
‘field1’:20
,‘field2’:10
,‘field3’:‘’
,‘field4’:null
}
]

Now for example in pseudo code:

if ( $field2 > 5 ) { delete($.field2) }
if ( $field3 == ‘’) {delete($.field3) }
if ( $field4 == null ) { delete($.field4) }

So now it looks like:

[
{
‘field1’:20
}
]

How can I do that? Note: I can achieve this with a JSON Generator using Apache Velocity, but I’m hoping there is a way to do this using something like a Mapper.

It would also be OK to do this in the opposite direction, e.g.,

if ( $input <= 4 ) { create($.field2, $input) }

Let me know if you have any questions,
Thanks!
Ish

5 REPLIES 5

Sorry, Aha is a mystery to us all. 🙂 Just reference the ticket in your communications with your CS or support rep.