我的输入是一个Array of Java Objects
:
[{"name"="Demo","platform"=[{"id"="1","value"="ios"},{"id"="2","value"="android"}],"language"=[{"id"="1","value"="eng"}],"date"="20/05/2018"}, {"name"="Kernel","platform"=[{"id"="1","value"="macos"},{"id"="2","value"="linux"}],"language"=[{"id"="1","value"="ger"}],"date"="20/05/2018"}]
每个Java Object
包含平台和语言键中的数组,例如以下示例:
{"name"="Demo","platform"=[{"id"="1","value"="ios"},{"id"="2","value"="android"}],"language"=[{"id"="1","value"="eng"}],"date"="20/05/2018"}
这是在text/plain
类型中预期的输出:
{"name":"Demo","platform":[{"id":"1","value":"ios"},{"id":"2","value":"android"}],"language":[{"id":"1","value":"eng"}],"date":"20/05/2018"}
{"name":"Kernel","platform":[{"id":"1","value":"macos"},{"id":"2","value":"linux"}],"language":[{"id":"1","value":"ger"}],"date":"20/05/2018"}
是否可以在不必使用String replace的情况下应用此功能?
答案 0 :(得分:3)
因此,您可以使用write函数将每个元素转换为application / json,并使用writer属性indent = false
%dw 2.0
output text/plain
---
payload map ((item, index) -> write(item, "application/json", {indent: false})) reduce ((item, accumulator) -> item ++ "\n" ++ accumulator)
或者,如果您使用的是m子4.2,则可以直接使用application/x-ndjson
,它应该可以直接使用
%dw 2.0
output application/x-ndjson
---
payload