One Star

How to output JSON records in multiple rows

Hi Experts,

I have generated a JSON output file using Talend. However, my problem is that all my records are outputted in 1 row in the JSON file. Below is the sample output:

My desired output is to have all JSON record separated by newline in the output file:

Thanks in advance for the feedback and help.
7 REPLIES
Four Stars

Re: How to output JSON records in multiple rows

replace "}," with "},\n"
One Star

Re: How to output JSON records in multiple rows

replace "}," with "},\n"

Thanks for the feedback.
But how do I process JSON file as plain text? When I try to process it, it is always filtered by column. For example, when I try to process the string, records are usually separated by field (field1, field2, field3) and not the whole string ({"field1":"value1_1","field2":"value2_1","field3":"value3_1"},{"field1":"value1_2","field2":"value2_2","field3":"value3_2"},{"field1":"value1_3","field2":"value2_3","field3":"value3_3"})
Four Stars

Re: How to output JSON records in multiple rows

After you wrote the json file, open it raw (tfileinputraw), read as string, searchn´replace in a tjavarowcomponent, write raw.
Take care about the Encoding
Seventeen Stars

Re: How to output JSON records in multiple rows

Oh dear... string manipulation to transform JSON? Seriously?
Why do you need to pretty print the output this way. For a technical usage of the file this does not makes sense. For the human read you can use tools which formats the file in a human readable way.
I would never ever manipulating the json content which such error prone methods.
Fifteen Stars

Re: How to output JSON records in multiple rows

We really need some sort of +1 or Like mechanism in here jlolling :-)
I have to say I agree with Jan, but maybe you can explain why you need the JSON in that format ctufindgood? It does seem like a weird requirement, but I have also had many weird requirements from clients :-)
Rilhia Solutions
Four Stars

Re: How to output JSON records in multiple rows

@jolli: hopy you didn´t called me a dear  ...
One Star

Re: How to output JSON records in multiple rows

Hi jlolling and rhall2.0,
Yes, it is for a technical usage. It needs to accept data in the format of JSON, but the separator (",") actually needs to be replaced by newline character (\n).
Many Thanks.