dw2.0可以从yaml属性文件中读取路径吗?
例如说输入是
{
"head": {
"country": "US",
"body": {
"USStates": {
"stateName": "California",
"stateCode": "CL"
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
我必须从上面的请求中获取 stateCode 值。根据国家名称,路径每次都会改变(如中国国家、印度国家等)
那么有没有办法将输入路径作为参数传递给 Data weave?我们正在使用 yaml 属性。我尝试了下面的代码,它导致空值
%dw 2.0
output application/json
---
if(p("countryName." ++ (payload.head.country as String)) != null)
payload.p("countryName." ++ (payload.head.country))
else "not in scope"
Run Code Online (Sandbox Code Playgroud)
在 yaml 中声明如下
countryName:
US : head.body.USStates.stateCode
INDIA : head.body.IndiaStates.stateCode
Run Code Online (Sandbox Code Playgroud)
我什至尝试从有效负载传递路径,然后将其作为字符串。请建议