How to verify and populate if the JSON object keys contains string

In this article, we are trying to verify if a string value is present in an ArrayList or keys of a JSON object. We have used "sizeOf", "keysOf" and "contains" to find out if the given string is present in any of the keys in a JSON object or an ArrayList.

Also Read: How to use contains operation in Object Store Mule 4



How to verify if a string value is present in an ArrayList using Mule Dataweave?


In the below example, We are trying to verify if the input payload contains "skillsList" as a key and populate the entire "skillsList" object as JSON output.



Dataweave code:
%dw 2.0
output application/json
var keys=keysOf(payload.users)
---
if ((sizeOf((keys)filter ($ contains "skillsList")) > 0) == true)
"skillsList":payload.users.skillsList
else ""




Post a Comment

0 Comments