Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
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
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.
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
@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
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:
Connect it with a tJavaRow.
tJavaRow should look like that inside:
>>>
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:
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
best regards
@odisys Thank you so much for this, this is really helpful