Search code examples
mysqlapimappingresponsetalend

TALEND: How to extract JSON response body from API into Table in Talend?


I create a job in Talend to extract data from an API to MySQL table. I used tRest as input(data pull), and tLogRow for now to view it in table form.

I lost it at mapping the json response into column for each of the field and value.

Sample from components I used in the job

but the response was in one string line, when it's prettier formatted:

{
 "data":
       {
        "user":
               [
                {"id":8, "name":"Alex"},
                {"id":9, "name":"John"}
               ]
        },
       "http_code":200,
       "message":[]
}

how can I turn this response and map into table like below

id name
8 Alex
9 John

Glad if you guys have the working example too. Or using different components might help?


Solution

  • Here's how to set up tExtractJSONFields:
    enter image description here

    Loop path query needs to be:

    $.data.user[*]
    

    And just use the attribute names as json query for for each column.
    The output:

    .--+----.
    |tLogRow_1|
    |=-+---=|
    |id|name|
    |=-+---=|
    |8 |Alex|
    |9 |John|
    '--+----'