我需要在 mule 中使用 dataweave 将现有的分隔 rune 件转换为 json 格式。
示例输入:
Name~#~ID~#~Company~#~Address
SRI~#~1~#~Infy~#~Bangalore
Rahul~#~2~#IBM~#~US
John~#~3~#~SF~#~UK
样本输出
{
Name: Sri
ID: 1
Company: Infy
Adress: Bangalore
},
{
Name: Rahul
ID: 2
Company: IBM
Adress: US
},
{
Name: John
ID: 3
Company: SF
Adress: UK
}
但是我的输出低于输出
数据编织转换
最佳答案
非常有趣的问题,您可以使用 dw::core::Binaries
中的 readLines
函数,然后按 ~#~
拆分。请记住将您的负载设置为 application/octet-stream
mimeType,这样 dw 会将其作为二进制数据处理,稍后您可以使用此代码段来解析它。
%dw 2.0
output application/json
import dw::core::Binaries
var lines = Binaries::readLinesWith(payload, "UTF-8")
---
lines match {
case [x ~ xs] -> do {
var header = x splitBy "~#~"
---
xs map ((item, index) -> {
(item splitBy "~#~" map (column, index) -> {
(header[index]): column
} )
})
}
}
关于json - 使用 Mule 中的 Dataweave 将定界文件转换为 JSON 格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64348854/