My input is an 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"}]
Each Java Object
contains arrays in Platform and language key like this example:
{"name"="Demo","platform"=[{"id"="1","value"="ios"},{"id"="2","value"="android"}],"language"=[{"id"="1","value"="eng"}],"date"="20/05/2018"}
This is the output expected in text/plain
type:
{"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"}
Is it possible to apply this without having to play with String replace?
So you can use the write function to transform each element to application/json and with the writer property indent=false
%dw 2.0
output text/plain
---
payload map ((item, index) -> write(item, "application/json", {indent: false})) reduce ((item, accumulator) -> item ++ "\n" ++ accumulator)
Or if you use mule 4.2 you can directly use application/x-ndjson
and it should work directly
%dw 2.0
output application/x-ndjson
---
payload