Easy way to skip the field(s) which is NULL – MuleSoft 4

Problem:

Sometimes to work with MuleSoft Anypoint Studio, we have payload with fields contain a null value.
For example:
Input Payload:

{

"id": 001,
"firstName": "John",
"lastName": null,
"phoneNumber": null,
"email": "abc@domain.com"

}

 

You want to keep the fields which have a value. You want to skip the NULL value fields.

Expected Payload:

{

"id": 001,
"firstName": "John",
"email": "abc@domain.com"

}

Solution:

You can do it very easily in ‘Transform Message / Data Weave’, in MuleSoft Anypoint Studio.

%dw 2.0
output application/json skipNullOn="everywhere"
{
"id": payload.'id', 
"firstName": payload.'firstName',
"lastName": payload.'lastName',
"phoneNumber": payload.'phoneNumber',
"email": payload.'email'

}

Just add skipNullOn=”everywhere” after ‘output application/JSON’

Note:

This attribute only works when the output is in JSON or XML. It will not work for output ‘java’.



 

Share This Post

Share on facebook
Share on linkedin
Share on twitter
Share on email

More To Explore

How can we help?

A little about yourself and we're ready to go

We pride ourselves on swift communication and prompt responses. Let us know what you're thinking and how we can help you.

Contact Information​

Head Office
75 Cornwall Drive, Ajax ON L1T3G2

Toronto Office
602 – 8133 Warden Ave, Markham, ON L6G 1B3, Canada

Phone: +14168902757
Email: info@plektonlabs.com

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.