1

I have the following input INPUT: JSON:

{
  "abc": ""
}

Expected output: XML:

<abc xsi:nil="true"/>

dataweave used:

%dw 2.0
output application/xml
ns xsi http://www.w3.org/2001/XMLSchema-instance
---
(if(payload.abc == "")
            (abc @(xsi#'nil': true):{})
        else
            null)

I am getting an error. Please help me with this
Sufi
  • 186
  • 1
  • 2
  • 12
  • What error do you get. That expression should work fine so far the value of abc is "" in the input. If its something else there would be an error since it would not be a well formed xml in the output. – Salim Khan Oct 31 '20 at 20:26

1 Answers1

0

You can use the 'writeNilOnNull' writer property when defining the dataweave output:

%dw 2.0
output application/xml writeNilOnNull=true
---
payload

Note that this property will only set nil for properties that are null (in the example you provided, empty string is not null).

The following screenshot shows this behavior:

DW writeNilOnNull example

olamiral
  • 1,296
  • 7
  • 8