Override skipNullOn="everywhere"

I have divided my dataweave script into modules, and I have used skipNullOn="everywhere" in the main dwl, so all the null values in all the modules are skipped. But, I don't want to skip the null values of a particular modules. How do I override(nullify) the skipNullOn="everywhere" for that particular module.

Input:

<XML xmlns:xsi="">
    <ABC xsi:nil="true"/>
    <DEF/>
</XML>

dataweave code:

%dw2.0
output application/json skipNullOn="everywhere"
---
payload.XML

Expected Output( json):

{
"ABC": ""
}

Getting Output(json):

{

}
2

3 Answers

Since I am answering it pretty late, I am not sure if this of much help to you. Anyways, you can have the list of nodes for which you want to skip the 'skipNullOn' check in a comma separated format in the property file. And then you try something similar as I have here below, which will help you iterate over all the nodes and then achieve the output as you desire:

%dw 2.0
output application/json skipNullOn="everywhere"
var toSkipNullOn='ABC,XYZ'

fun checkNull(key,val) = if((toSkipNullOn splitBy(',')) contains(key as String)) ''  else null
---
payload.XML mapObject (v0, k0, i0) -> 
{
    (k0):checkNull(k0,v0) 
}

In this example I have hardcoded the node names (ABC,XYZ) to the variable toSkipNullOn. Instead of that you'll have to read it from the property file as p('key-name') and assign it to toSkipNullOn.

You need to explicitly write the logic for that field, should be something like this

%dw2.0
output application/json skipNullOn="everywhere"
---
{
"ABC": if (payload.XML.ABC_val !=null ) else ""
}
2

You can try this workaround, to get the expected result. Use two dataweave

1st Dataweave (wherever you get "nil", syntax need to be updated as the below one)

%dw 2.0
output application/xml skipNullOn="everywhere"

ns xsi 
---
{
ABC @( xsi#nil:"true"): payload.ABC ,
DEF : payload.DEF
}

2nd Dataweave

 %dw 2.0
output application/json
---
payload

You can then replace null with "" easily.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

James H. Sterling

James H. Sterling

Environmental Science & Climate Journalist

James Sterling reports on renewable energy developments, climate policy, ecological conservation, and green tech innovations around the globe.

Share this article
Twitter Facebook Pinterest