admin管理员组文章数量:1279234
I want to do a selection on an item based on a (yaml) property in Dataweave. I have this code:
%dw 2.0
var testWithProperty = p('incoming.var')
// incoming.var refers to the value "resultSet"
var inPayload = [
resultSet: {
id: "some Id"
},
resultSet: {
id: "some other Id"
}
]
output application/json
---
{
"result1": inPayload..resultSet,
"result2": inPayload..testWithProperty
}
result right now is like this:
{
"result1": [
{
"id": "some Id"
},
{
"id": "some other Id"
}
],
"result2": null
}
result2 is null.
The result should be this:
{
"result1": [
{
"id": "some Id"
},
{
"id": "some other Id"
}
],
"result2": [
{
"id": "some Id"
},
{
"id": "some other Id"
}
]
}
How can I use a property in such a case on a selection ?
I want to do a selection on an item based on a (yaml) property in Dataweave. I have this code:
%dw 2.0
var testWithProperty = p('incoming.var')
// incoming.var refers to the value "resultSet"
var inPayload = [
resultSet: {
id: "some Id"
},
resultSet: {
id: "some other Id"
}
]
output application/json
---
{
"result1": inPayload..resultSet,
"result2": inPayload..testWithProperty
}
result right now is like this:
{
"result1": [
{
"id": "some Id"
},
{
"id": "some other Id"
}
],
"result2": null
}
result2 is null.
The result should be this:
{
"result1": [
{
"id": "some Id"
},
{
"id": "some other Id"
}
],
"result2": [
{
"id": "some Id"
},
{
"id": "some other Id"
}
]
}
How can I use a property in such a case on a selection ?
Share Improve this question edited Feb 25 at 0:11 eglease 2,75411 gold badges20 silver badges34 bronze badges asked Feb 24 at 9:55 BenBen 7421 gold badge11 silver badges34 bronze badges 1 |1 Answer
Reset to default 2You need to use Dynamic Selector for this.
{
"result1": inPayload..resultSet,
"result2": inPayload..[testWithProperty],
"result3": inPayload.."$(testWithProperty)"
}
When you do inPayload..testWithProperty
it will look for the property testWithProperty
and will not resolve the testWithProperty as a variable. When you use Dynamic Selector inPayload..[testWithProperty]
OR inPayload..'$(testWithProperty)'
it the value will be evaluated as you need.
本文标签: propertiesMulesoft Dataweave use a variable as item in a selection at a JSON objectStack Overflow
版权声明:本文标题:properties - Mulesoft Dataweave use a variable as item in a selection at a JSON object - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741281265a2370021.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
inPayload.*resultSet
. – aled Commented Feb 24 at 12:54