How to Retrieve and Process JSON Data from a REST API in Talend

How to Retrieve and Process JSON Data from a REST API in Talend

Are you working as a Data Engineer, and have you started using Talend? Maybe in one of your projects, you need to retrieve data from a REST API and process it inside Talend. The primary objective is to connect to the API, verify the request’s success, and extract specific fields from the JSON response.

Talend provides built-in components that simplify this process, such as tRestClient for calling APIs and tExtractJSONFields for parsing JSON.

Understanding the REST API

A REST API is a service that allows applications to exchange information. When you request data from it, the API sends back a response, often in JSON format, which is structured as key-value pairs and is easy to process.

→ APIs offer different operations as follows:
→ GET – to retrieve data
→ POST – to send new data
→ PUT/PATCH – to update existing data
→ DELETE – to remove data

In this article, we will use GET because we only need to read data.

Using tRestClient to Call the API

The tRestClient component is responsible for sending the request and capturing the response.

1. Drag tRestClient into your Talend job.
2. In Basic Settings, configure:
→ Endpoint: the path to the resource you want to access (in our case, a dummy API returning a sample JSON).
→ Method: GET.
→ Accept Type: application/json to request JSON as the response format.
3. (Optional) Add any necessary headers. For example, authentication or custom request parameters.
4. Link tRestClient to tLogRow temporarily to check the raw output.

The tRestClient provides:
statusCode – The response status (e.g., 200 for success, 404 for not found)
body – The actual JSON content returned

Extracting Fields with tExtractJSONFields

The API returns JSON data, but often it contains many fields we don’t need. We use tExtractJSONFields to parse the response and select only what’s relevant.

1. Add tExtractJSONFields and connect it to tRestClient.
2. In Basic Settings:
JSON field: choose the column containing the API’s JSON response.
Loop JSONPath query: $ (this means starting from the root of the JSON).
Mapping: define the fields you want, for example:
→ $.firstName
→ $.lastName
→ $.address.city
3. Assign a data type to each field:
→ String for text
→ Integer for numbers
→ Date for date fields

Logging and Error Handling

To visualise the results, link tExtractJSONFields to tLogRow and set display mode to Table for better readability.

For error handling, we suggest you use the error output from tRestClient to capture and log any failed calls. This allows you to store details like the error message and code for debugging.

Example Job Flow

→ tRestClient can connect to the API and retrieve JSON data.

→ tExtractJSONFields parses JSON starting from $ and extracts only the required fields.

→ tLogRow is the one who displays the clean output in table format.

→ Error flow is responsible for logging API request issues.

Watch the video tutorial here:

Result

This is what happens when you run the job:
→ A successful call will show statusCode 200.
→ The parsed fields will appear neatly in the console.
→ If the call fails, the error details will be recorded.

In conclusion, retrieving data from a REST API and processing it inside Talend it’s an easy job. The primary objective is to connect to the API, verify the request’s success, and extract specific fields from the JSON response.

About btProvider:

We hold all possible technical and sales certifications for all products:

TalendTableau Desktop, Tableau Public, Tableau Server, Tableau Prep, Tableau Data Management, VerticaSalesforceMulesoftWrite-Back.

With Talend – the best data management platform – you can always understand your data better. Using Talend, you will make intelligent and strategic decisions and seamlessly integrate, assure quality, and govern your data effortlessly. See other #skillpill video tutorials here:

How to create a Barcode Chart

How to create a top N Set

Using measure names in parameter actions

Are you interested in learning more about Talend – the catalyst for efficient and comprehensive data management solutions across your company?

Contact us!