Search code examples
jsondatabaseresttalend

Read multiple JSONs from single REST Service response and put to Database Table - Talend


enter image description hereI have searched a lot but not found exact slution. I have a REST service, in response of which I get rows and each row in a JSON, as given bellow:

{"event":"click1","properties":{ "time":"2 dec 2018","clicks":29,"parent":"jbar","isLast":"NO"}}
{"event":"click2","properties":{ "time":"2 dec 2018","clicks":35,"parent":"jbar3","isLast":"NO"}}
{"event":"click3","properties":{ "time":"2 dec 2018","clicks":10,"parent":"jbar2","isLast":"NO"}}
{"event":"click4","properties":{ "time":"2 dec 2018","clicks":9,"parent":"jbar1","isLast":"YES"}}

Each row is a JSON (all are similar to each other). I have a database table having all those fields as columns. I wanted to loop through these and upload all data in Talend. What I have tried is following:

tRestClient--tNormalize--tExtractJsonFields--tOracleOutput

and provided loop criteria and mapping in tExtractJsonFields component but it is not working and throwing me error saying "json can not be null or emptyenter image description here" Need help in doing that.


Solution

  • Since your webservice returns multiple json objects in the response, it's not valid json but rather a json document.
    You need to break it into individual json objects.
    You can add a tNormalize between tRESTClient and tExtractJsonFields, and normalize the json document on "\n" character.
    The error "json can not be null or empty" is due to an error in your Jsonpath queries. You have to set the loop query to "$", and reference the json properties using "event", "properties.time"