Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hi,
I am trying to extract some JSON fields after a REST request but somehow I am not able to get the correct values. This is the job:
The value for version in tLogRow_3 is always empty
The JSON looks like this:
{
"results": [
{
"attributes": {
"name": "myName",
"description": 0.0,
"version": 1.0
}
}
]
}
With tLogRow Talend prints the following:
<?xml version="1.0" encoding="UTF-8"?> <root><results><attributes><name>myName</name><description>0.0</description><version>1.0</version></attributes></results></root>
Now I want to extract the value for version by using tExtractJSONFields
I also get the following error message:
Expected to find an object with property ['results'] in path $ but found 'java.lang.String'. This is not a json object according to the JsonProvider: 'com.jayway.jsonpath.spi.json.JsonSmartJsonProvider'.
Talend can't print the value and I don't know what I am doing wrong. Would appreciate any help.
Regards,
Basit
Your problem is with the tRestClient. You need to go to the Advanced Settings and untick "Convert Response To DOM Document". This is used to convert JSON to an XML document. You will also need to switch the column that your tExtractJSONFields component reads to the "string" column. JSON is returned as a String and XML as a Document (body).
Your response is coming as xml, but you're trying to parse it as json. Use the http header
Accept: application/json
to get a response in JSON format
Hi @evansdar,
I am already using this header. Somehow tLogRow prints it that way. Don't know why...
I think the issue is something else.
Your problem is with the tRestClient. You need to go to the Advanced Settings and untick "Convert Response To DOM Document". This is used to convert JSON to an XML document. You will also need to switch the column that your tExtractJSONFields component reads to the "string" column. JSON is returned as a String and XML as a Document (body).
Hi @rhall,
you are right! Totally forget about configuring that. I was just focused on the tExtractJSONFields component. Thank you
No problem. It is easily overlooked 🙂