Ritesh Kaushik
Ritesh Kaushik

Reputation: 735

Talend read JSON data from tRESTRequest

I am trying to learn Talend.

Scenario: I have to create a REST endpoint (i am using tRESTRequest) which takes a POST request at http://localhost:8086/emp/create and accepts below json and prints each json field and sends a sample json response containing only name field.

  1. How can I do so ?

  2. How to read the json data into a java component like tJava?

Structure:

{
"emp" : 
 [ 
    {
      "id":"123",  
      "name": "testemp1"
    },
    {
        "id":"456", 
        "name": "testemp2"
    }
  ]
}

Expected Response:

{
"emp" : 
 [ 
    {
       "name": "testemp1"
    },
    {
       "name": "testemp2"
    }
  ]
}

I am using tRESTRequest -> tExtractJSONFields -> tRESTResponse.

Upvotes: 1

Views: 1744

Answers (1)

tobi6
tobi6

Reputation: 8239

For looping on the right elements and parsing the contents, please see my answer JSON Deserialization on Talend

I did not understand the second question. When deserializing JSON, the data will already be available in the usual row format for processing further. Beginner tutorials will show you the standard structure. The component tJava is - of course - an exception to that rule. Handling data is different in this component and not neccessarily row based.

Talend has an excellent knowledge base for components and examples, see https://help.talend.com/

Upvotes: 1

Related Questions