Tuesday, May 23, 2017

Mule Dev Tricks: Create An Array List From JSON Using DataWeave

Input

[
 {
  "id" : "11111",
  "name" : "AAAAA"
 },
 {
  "id" : "22222",
  "name": "BBBBB"
 },
 {
  "id" : "33333",
  "name" : "CCCCC"
 }
] 

Output

["11111", "22222", "33333"]
As you can see, we only want to extract the id from the input.

DataWeave Script

%dw 1.0
%output application/java
---
payload map (data) -> data.id

The map function from the Dataweave component is the mostly used function. Here we using a simple lamda expression to extract id. Another simple way is:
payload map $.id  

1 comment:

  1. Very informative post for mulesoft developers.You can also visit goformule.com for mulesoft stuff.

    ReplyDelete

Anypoint Studio Error: The project is missing Munit lIbrary to run tests

Anypoint Studio 7.9 has a bug. Even if we following the article: https://help.mulesoft.com/s/article/The-project-is-missing-MUnit-libraries-...