In my flow, I read and run (for-each) an array of JSON objects. I insert each object in the same file with APPEND type.

enter image description here

I want to store each JSON with indent as false (one line by JSON) and a carriage-return like this example:




I use this:

%dw 2.0
 output application/json indent=false
 payload ++ '\r'

But it returns an error about cannot coerce Object to String. How can I solve this?

1 Answer 1


application/json is technically an object, not a string. So you cannot concatenate directly.

This works for me, to get the desired result:

%dw 2.0
output application/java
write(payload, "application/json", {"indent":false}) as String ++ '\r'

write as json first to use the writer property to remove indentation then convert to string and concatenate and output as String application/java

Not the answer you're looking for? Browse other questions tagged or ask your own question.