December 8, 2019

How to remove specific key and its value from JSON in MuleSoft using DataWeave?

Sample Code:

  1. %dw 2.0  
  2. output application/json  
  3. ---  
  4. payload filterObject ((value, key) -> (key as String != "Test"))  

In the above code
1. filterObject is used to filter JSON payload.
2. key as String is used since key is not an equivalent to String.
3. != is used to select all keys and values except "Test".

The above code removes key "Test" and it's values from the payload.

2 comments: