Reputation: 89
I am trying to match specific values from payload and return only the matched array value using dataweave expression.
Input:
name: QA
Payload:
{
"kind": "drive#driveList",
"nextPageToken": "~!!~AI9FV7TFuXfzyGg-txFqJWTa2oDXcgJ3ULdaNmst8",
"drives": [
{
"kind": "drive#drive",
"id": "0AKrgo4Gdm2hzUk9PVA",
"name": "Dev"
},
{
"kind": "drive#drive",
"id": "0AGymmOhxiCGwUk9PVA",
"name": "EHS Safety - Public"
},
{
"kind": "drive#drive",
"id": "0AAD3jo6D8PX-Uk9PVA",
"name": "Job Master folder"
},
{
"kind": "drive#drive",
"id": "0AI1WUfEk8cWkUk9PVA",
"name": "MSTemplates"
},
{
"kind": "drive#drive",
"id": "0AC_FdkeL63mHUk9PVA",
"name": "QA"
}
]
}
Expected output should be like output:
{
"kind": "drive#drive",
"id": "0AC_FdkeL63mHUk9PVA",
"name": "QA"
}
how can i achieve this?
Upvotes: 1
Views: 409
Reputation: 1296
You can use the following dataweave expression:
%dw 2.0
output application/json
---
payload.drives filter ((item, index) -> item.name == 'QA')
Output:
[
{
"kind": "drive#drive",
"id": "0AC_FdkeL63mHUk9PVA",
"name": "QA"
}
]
Note that the resulting payload will be an array of "drives" items.
Upvotes: 5