1

how to remove specific fields from map using dataweave

input:

{ a:1, b:2, c:3, d:4 }

I want to remove c and d fields(c and d values are dynamic) and display only output

{ a:1, b:2 }

How can we do it in data weave

Gopi
  • 105
  • 1
  • 7
  • 24

2 Answers2

5

According to the Dataweave Reference Documentation, you can remove a field from an object. Try using this:

%dw 1.0
%output application/json
---
payload - "c" - "d"
1

Below code works fine:

%dw 2.0
var arr=["c","d"]
output application/json
---
payload filterObject ((value, key, index) -> !(arr contains  (key) as String))

You can add/remove the keys that you want to exclude in the variable 'arr'.

Aditya
  • 11
  • 2