How to append fields in mule dataweave to existing json payload

Viewed 1906

Exisiting Json { a:1, b:2 }

Add the field c:3

Final Output expected { a:1, b:2, c:3 }

2 Answers
%dw 2.0
output application/json

---

{ a:1, b:2 } ++ {c: 3}

Sample Output:

{
  "a": 1,
  "b": 2,
  "c": 3
}

You can directly keep payload as it is and add the new JSON field as below:

payload ++ {c:3}

output:
{ 
 a:1,
 b:2, 
 c:3 
}
Related