WebFeb 29, 2024 · I would like to filter an array of keys from an object. Please help to achieve this using Dataweave 2. Input: { "name":"Mule", "email":"[email protected]" "phone":57673564, "zip":43534, "gender":"male" } From the above example I would like to filter only keys matching with my array (ex: ["email","phone","zip"]) Output { "email":"[email protected]" WebIn this case, since v and k are the first and second parameters, we can also use the following code: 1 2 3 4 5 6 %dw 2.0 output application/json --- payload mapObject ( (v,k) …
Remove Objects Containing Specified Key-Value Pairs
WebJan 6, 2024 · 3 Answers. Based on another comment you made, I don't think what you're asking for is built into the language, though there are some interesting functions in the library related to the update function. A basic implementation of what you want might look like this: %dw 2.0 fun getField (payload: Any, field: String) = do { var path = field splitBy ... WebJan 16, 2024 · So let see how to do the positive and negative filtering in DW. Negative filtering. In DataWeave we have two operators – and –. The first one allows for removing a key-value pair by providing the key. ... filterObject function is the best match for that case. This function iterates over each key and applies lambda expression. If the ... electric-gold.com
Dataweave Filter Function - DZone
WebUsing filterObject we can Iterates a list of key-value pairs in an object and applies an expression that returns only matching objects, filtering out the rest from the output. … WebThe filterObject function works in a similar fashion to the filter function, however, instead of returning an array, it lists out the key-value pairs in an object and applies an expression that returns only the matching objects. If the expression provided has no matches, the output will return an empty object. ... WebNov 11, 2024 · After that you will notice that the filter is expecting a single object, but because it is an array you need to map it first. To return a single array I used a flatMap (): %dw 2.0 output application/json --- payload flatMap $.drives filter ( (item, index) -> item.name == 'Dev2024-10') Output: electric gold rolling machine