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

plektonlabs partner with noname security
News

PlektonLabs Partners with Noname Security

Partnership seeks to solidify mutual commitment to ensuring API security Toronto, 8 April 2022: PlektonLabs and Noname Security announced today that the companies have entered

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
18 King Street E, Suite 1400, Toronto ON M5C 1C4, Canada

USA Office
5900 Balcones Dr, 100, Austin, Texas 78731, USA

Phone: +1(877) 855-8775
Email: info@plektonlabs.com

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