如何根据特定条件过滤 dataweave 中的响应?
How do I filter the response in dataweave based on a certain criteria?
假设我从 API 呼叫中收到以下响应。
accounts: [
accountName: "A",
amount: 10$
account Name "B closed",
amount: 20$
]
我想过滤所有在帐户名称中包含 closed 关键字的帐户响应。谁能告诉我如何根据此过滤所有包含已关闭的响应并只给我帐户 A.
我正在为我的 mulesoft 代码使用 dw 1.0。如果您还有其他问题,请告诉我。
假设您的输入是:
{
"accounts": [
{
"accountName": "A",
"amount": "10$"
},
{
"accountName": "B closed",
"amount": "20$"
}
]
}
然后你可以这样过滤:
%dw 1.0
%output application/json
---
payload.accounts filter ((account) -> not (account.accountName contains "closed"))
这将导致:
[
{
"accountName": "A",
"amount": "10$"
}
]
假设我从 API 呼叫中收到以下响应。
accounts: [
accountName: "A",
amount: 10$
account Name "B closed",
amount: 20$
]
我想过滤所有在帐户名称中包含 closed 关键字的帐户响应。谁能告诉我如何根据此过滤所有包含已关闭的响应并只给我帐户 A.
我正在为我的 mulesoft 代码使用 dw 1.0。如果您还有其他问题,请告诉我。
假设您的输入是:
{
"accounts": [
{
"accountName": "A",
"amount": "10$"
},
{
"accountName": "B closed",
"amount": "20$"
}
]
}
然后你可以这样过滤:
%dw 1.0
%output application/json
---
payload.accounts filter ((account) -> not (account.accountName contains "closed"))
这将导致:
[
{
"accountName": "A",
"amount": "10$"
}
]