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: 
HVasa1630039830
Contributor
Contributor

How to read multiple json objects which is not an json array in talend

Hi All ,

iam new to talend try to learn things any help would be much appreciated

Iam trying to read multiple json objects present in single file in to a table by dividing the values through textractJsonfield component

My current job is picking only first json value and writing the same to database below is the flow i used

tfileInputDelimeted --> textractJsonFields ---> db

my file format is as below :

{tranid:"1212", "user":{"name":"123","addr":"786 rt"}}

{tranid:"1213", "user":{"name":"345","addr":"4234 iu"}}

my input file has the json objects as above .. if its like array i was able to read all the data thrgh extractjson component with no issues ,but the real thing comes up when its not an array of objects and it is reading only the first object which is tranid:1212 data

Labels (3)
6 Replies
Anonymous
Not applicable

I have written a job where this works. It looks like below. You can see the result of running it as well (I added an extra row of data to the data you supplied)....

0695b00000Hur5YAAR.pngMy tExtractJSONField was configured like this....

0695b00000Hur5dAAB.png 

Does that point you towards where your job needs to be updated? If not, can you post more details about your job?

HVasa1630039830
Contributor
Contributor
Author

Hi Thanks for the reply ..

 

I have tried the smae earlier but it was reading only the first object of json not the second one .. what properties you defined for the component of extractjsonfield to loop for the second json object ??

 

as the below two json objects are seperatly flowing in how you looped through them ?? for tranid 1212 and tranid 1213??

 

{tranid:"1212", "user":{"name":"123","addr":"786 rt"}}

{tranid:"1213", "user":{"name":"345","addr":"4234 iu"}}

 

 

Anonymous
Not applicable

The looping in this case isn't down to the tExtractJSONFields component. The looping is actually handled by the tFileInputDelimited. Each JSON file is on a different row of the file. So the tFileInputDelimited is returning a row for each JSON snippet. I suspect that maybe your tFileInputDelimited may need its row separator changed. Mine is set to the default of "\n".

HVasa1630039830
Contributor
Contributor
Author

Sorry for the delayed response .. but some how in my case i was parsing the json objects and is reading only the first json value until or unless they are bounded together as json array .. if its a json aray it is able to loop all the elements

 

 

HVasa1630039830
Contributor
Contributor
Author

Can you please provide me the exact json file you are trying to read ???

Anonymous
Not applicable

My file looks exactly like this.....

 

{tranid:"1212", "user":{"name":"123","addr":"786 rt"}}

{tranid:"1213", "user":{"name":"345","addr":"4234 iu"}}

{tranid:"1233", "user":{"name":"33545","addr":"4w3234 iu"}}

 

Each row is a ew JSON String. I assumed that is how yours is.