One Star

[resolved] tRestRequest with JSON Parameter

Hello,
i'm having problem to develop a simple REST service call where i pass to it a JSON information in one of the fields and print it on the console the table result with the data. The questions and the problem are:
- I don't know what the kind of the field on Output flow parameters, have tried Object, Document and String but doesn't work.
- Is it possible to do that on talend open studio for ESB?

Json:{"Aluno":}

  • ESB
20 REPLIES
Moderator

Re: [resolved] tRestRequest with JSON Parameter

Hi,
Please have a look at the online component reference TalendHelpCenter:tExtractJSONFields
Best regards
Sabrina
--
Don't forget to give kudos when a reply is helpful and click Accept the solution when you think you're good with it.
Four Stars

Re: [resolved] tRestRequest with JSON Parameter

Hello lecom
I am trying to do something similar, ie retrieving a JSON file using tRESTRequest and parsing it with tExtractJSONFields.
Did you succeed in your case?
If so can you describe how you achieve it?
thanks in advance for your help.
Employee

Re: [resolved] tRestRequest with JSON Parameter

Hi
Given ":{"Aluno":}",
if we use tRESTRequest, accepting/consuming JSON, with the body type set to Document, then connecting it to tXMLMap will do the internal JSON to XML auto-conversion;
I guess we will have something like this in XML:

João
Maria
Pedro

tXMLMap should help you handle it further.
Alternatively, set tRESTRequest body type to String and feed it into one of Studio components reading JSON
HTH, SErgey
One Star

Re: [resolved] tRestRequest with JSON Parameter

Hello, I have a similar challenge on a requirement for a REST POST service, with tRestRequest reading a JSON POST payload and writing the results to an Oracle database. 
I tried tExtractJsonFields directly linked to tRestRequest and it seems unable to read the column nodes despite various xpath combinations. My tLogRow comes up empty. The same message is readable from a saved (on disk) JSON file using tFileInputJson, but we need this to be from an incoming tRestRequest.
I looked into tWriteJsonField as well, but just like the documentation on tExtractJsonFields, it doesn't seem any of these Talend JSON components can take tRestRequest strings and convert them into columns writeable to relational database.
Can somebody point out an example of how this works and confirm what components can read directly from tRestRequest? tXMLMap is unable to import JSON metadata, just XML so it doesn't seem to be the proper approach either?
Employee

Re: [resolved] tRestRequest with JSON Parameter

Hi
If you link tXMLMap to tRESTRequest then the incoming JSON will be auto-converted to XML, a given tRESTRequest flow's schema should have a 'body' of type 'Document' set for it to work.
Alternatively, set a body type to String, log it to confirm you have a payload coming in, and then process as needed...
Cheers, Sergey
One Star

Re: [resolved] tRestRequest with JSON Parameter

Thank you for the confirmation, Sergey. This method.."Alternatively, set a body type to String, log it to confirm you have a payload coming in, and then process as needed.." ..was as per your last post.  
We prefer not to convert to XML and then to SQL. Can you explain or have examples on how we convert the incoming JSON payload in a String directly to SQL database? It seems the current transformation components read from a fixed file, not from a tRestRequest directly. I have tried various combinations using tExtractJsonFields and it just comes out null.
One Star

Re: [resolved] tRestRequest with JSON Parameter

I have been able to use tXMLMap but don’t know what follows  “..process as needed.” Would you kindly offer an example of what t component(s) to use right after tRestRequest? I have not been able to make tExtractJsonFields work and am thinking it’s not proper to link directly to the Request? The JSON body never appears to make it to the component. Here are my screenshots of the job design and component definitions
Community Manager

Re: [resolved] tRestRequest with JSON Parameter

Hi 
What is the data type of body on tRestRequest? Try to check the 'log message' box in the advanced setting panel of tRestRequest to print the log message on the console, so you could see the exact data received by the web service. Such us:
ID: 1
Address: http://localhost:8088/
Encoding: ISO-8859-1
Http-Method: POST
Content-Type: application/json
Headers: {Accept=, Cache-Control=, connection=, Content-Length=, content-type=, Host=, Pragma=, User-Agent=}
Payload: {"person":{"id":1,"name":"shong"}}

Best regards
Shong
----------------------------------------------------------
Talend | Data Agility for Modern Business
One Star

Re: [resolved] tRestRequest with JSON Parameter

Hi SHong, I have clipped the output from tRestRequest. 
tRestRequestSpool.txt.txt
Employee

Re: [resolved] tRestRequest with JSON Parameter

Hi
A direct tRESTRequest to tXmlMap link should work; tRESTRequest would auto-convert JSON to DOM4J and tXMLMap would deal with it. I do not have a demo job available right now, sorry. When I said "process as needed" I referred to the alternative option, where no tXMLMap is used but tExtractJsonField is used instead - I've no experience of working with that component though.
Cheers, Sergey
One Star

Re: [resolved] tRestRequest with JSON Parameter

Thanks for your clarification. I just need to know if this is the ONLY way to process incoming REST requests, exploring as wide a range of TOS ESB's capabilities in our POC, comparatively to other ESBs like Mule, Informatica.
Employee

Re: [resolved] tRestRequest with JSON Parameter

Np, it is def not the only way, as far as the parsing of the incoming JSON requests is concerned. The 2 options we've discussed are about extracting the individual properties from a JSON payload. One can also get a String payload and process it with a favourite JSON library from tJava or save it directly if needed. I'm referring to tXmlMap because I was a bit involved in the relevant development but indeed auto-converting to tXMLMap is not the only option
Cheers, Sergey
One Star

Re: [resolved] tRestRequest with JSON Parameter

Thank you. tJava is custom and certainly a way to hand-code. Would it be safe to assume from a prebuilt Talend component point-of-view that none of tExtractJSONfields, tWriteJSONFields, (tFileInputJSON reads in json) nor any other t*JSON* Talend component can extract JSON payload from tRestRequest? If so, we can continue to use tXMLMap.
Employee

Re: [resolved] tRestRequest with JSON Parameter

The example at
https://help.talend.com/display/TalendComponentsReferenceGuide54EN/tExtractJSONFields
suggests that tWritejsonfield produces a String that is then fed into tExtractJsonField.
So as I said you can set a given tRESTRequest's flow schema to have bodySmiley Frustratedtring and have tExtractJsonField directly connected to tRESTRequest.
Another alternative is to use an advance mapping component,
http://www.talend.com/advanced-mapping-and-transformation
I believe it is available via a separate download...
One Star

Re: [resolved] tRestRequest with JSON Parameter

Thanks Sergey. I am trying exactly that--a tRestRequest linking its body flow to tExtractJsonFields but somehow not yielding. Let me attach screenshots of my configuration and perhaps I am missing something obvious?
tRestRequest_to_toExtractJSONFields.txt.txt
One Star

Re: [resolved] tRestRequest with JSON Parameter

Thank you both, Sergey and SHong, for your patience and confirming tExtractJSONFields works linked directly after tRestRequest. Even as I posted, realized my own mistake. I fully qualified the xpath "Consents/consent" again (as I tried it earlier under different circumstances), cleared the GetNodes and GetArray checkboxes and now it works. 
You may close this now.
Community Manager

Re: [resolved] tRestRequest with JSON Parameter

OK, thanks for your feedback!
Shong
----------------------------------------------------------
Talend | Data Agility for Modern Business
One Star

Re: [resolved] tRestRequest with JSON Parameter

Thank you both, Sergey and SHong, for your patience and confirming tExtractJSONFields works linked directly after tRestRequest. Even as I posted, realized my own mistake. I fully qualified the xpath "Consents/consent" again (as I tried it earlier under different circumstances), cleared the GetNodes and GetArray checkboxes and now it works. 
You may close this now.

Hi Mlting, Could you please post a video how to get JSON fields directly from tRestRequest's payload. Here you concluded that you achieved success. But I was struck here. Thanks in advance.
One Star

Re: [resolved] tRestRequest with JSON Parameter

Hi Mlting, 
Same here. I am too stuck at the same point. It would be helpful if you can share a video or sample job.
Thanks,
Ashish
Employee

Re: [resolved] tRestRequest with JSON Parameter

The column name of the schema of the Output Flow should be called body instead of payload.