0

I am trying to convert Array object to String using Dataweave-2.0 with the below input and output.

Input :

[
{"Name":"Sam","language":"Java","Id":"101"},
{"Name":"Ryan","language":"C","Id":"104"},
{"Name":"Sarah","language":"C","Id":"109"},
{"Name":"Rose","language":"Java","Id":"103"}
]

My output should be: Name Sam language Java Id 101 Name Ryan language C Id 104 Name Sarah language C Id 109 Name Rose language Java Id 103

I am unable to get the expected output. Any help is appreciated in advance. Thanks

2 Answers 2

2

Something like this should work:

(payload flatMap ($ pluck ($$ ++ " " ++ $))) joinBy  "   "

Output

"Name Sam   language Java   Id 101   Name Ryan   language C   Id 104   Name Sarah   language C   Id 109   Name Rose   language Java   Id 103"
Sign up to request clarification or add additional context in comments.

3 Comments

Yes, its working. Thanks a lot, Stevens. One more question - Is there a possibility to remove the quotes in the output?
Yes, You can achieve above without double quote by keeping output type: output application/java or text/plain
Got it. Thanks Manish
0
%dw 2.0 
output text/plain 
---
( 
   payload map ((item, index) ->item mapObject ((value, key, index) ->{ 
              "str": key ++ " "++ value 
               }))reduce ((item, accumulator) ->accumulator ++ item)
).*str joinBy " "

1 Comment

As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.