转义数据编织中的反斜杠

escape backslashes in dataweave

我在属性文件中有一个字符串数组,我想以 JSON 格式读取 dataweave 中的值。

属性文件中的数组是-

Countries = ["USA","England","Australia"]

dataweave中,我正在使用这个-

%output application/json

---
{
countries: p('Countries')
}

我得到的输出是-

"countries": "[\"USA\",\"England\",\"Australia\"]",

我想要的输出是-

"countries": [
    "USA",
    "England",
    "Australia"
  ]

我试过 replace 但没有成功。

在将国家/地区数组更改为 Countries = ['USA','England','Australia'] 后,我也尝试了 countries map $ as String,但它显示 Invalid input 'S', expected :type or enclosedExpr

如何实现?

问题是属性文件的值是字符串而不是数组,因此您的表达式不会被解释。不过不用担心,您可以使用读取功能 读(p('Countries'), "application/json"))