Skip to main content
Announcements
Join us at Qlik Connect for 3 magical days of learning, networking,and inspiration! REGISTER TODAY and save!
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

Convert Json data to csv format

Hi All,

 

I have my input as json file and I need to convert the same as csv format. Could you please help me on the same?

Can we use tExtractJSONFields ? 

 

Thanks in advance

Labels (4)
13 Replies
Anonymous
Not applicable
Author

Hi AlokGarg,

 

there is still problem with your multiple records file.

It misses the comma after the first (or before the second) "object" (object = the structure that starts with Request_Time).

Also you need array brackets around your whole structure because you have multiple objects on the same hierarchy level.

I have added a file with the corrected version.

 

Because this is more a JSON than a Talend question, i would recommend you to check your file/files first whether they are correct. I am using an online tool where you can post your json, execute JSON-Path queries and see the results.

 

http://www.jsonquerytool.com/

 

there are othe tools/webpages out, just google for it, if you need another.

 

Post your structure and enter some queries like: 

 

$.*

$[0].Location

$[0].Data_Layer[0].products[2]
$[0].Data_Layer[0].products[*].name

 

I did not look at your Talend Job, first the JSOn has to be corrected.

 

Best regards,  odisys

 

 

 

 

 


corrected_file_with_multiple_record.txt
Anonymous
Not applicable
Author

@odisys Thank you so much for your reply, I corrected the file manually and I could run the job successfully, but the input file I am getting is coming in the format I have posted, without ' [ ' in starting and no ' , '  separating the multiple JSON objects in the file, is there a way I can handle it in my JSON components, or is there a way to modify that raw file using any talend component and loading it to another JSON file with the proper format?

 

Thanks,

Alok

Anonymous
Not applicable
Author

Hello @AlokGarg

 

A little bit of  quick and dirty java code in a tJavaRow e.g. should do it.

 

Read  your original JSON file by tFileInputRaw component:

 

0683p000009LzOu.jpg

 

Connect it with a tJavaRow.

tJavaRow should look like that inside:

 

0683p000009LzHy.jpg

 

>>>

String newJSON = input_row.content.toString();

// add "," to root repeating objects
newJSON = newJSON.replace("{\"Request_Time\":", ",{\"Request_Time\":");
// remove "," from first root repeating object
newJSON = newJSON.replaceFirst(",", "");
// add array brackets
newJSON = "[" + newJSON + "]";

output_row.content = newJSON;


// System.out.println(newJSON);

>>>

 

connect tJavaRow to fileOutputRaw component:

 

fileOutputRaw like that:

 

0683p000009LzRK.jpg

 

 

Parse your new JSON file instead of the original one.

 

Tell the guys from the source-system which produce the JSON to deliver correct data to you

in the future 0683p000009MACn.png

 

 

 

best regards

Anonymous
Not applicable
Author

@odisys Thank you so much for this, this is really helpful 0683p000009MACn.png