Skip to main content
Announcements
Accelerate Your Success: Fuel your data and AI journey with the right services, delivered by our experts. Learn More
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

[resolved] Need to convert JSON string to document for use in tRESTClient

Hello,
In Talend Data Integration 5.6, I get the following error on compilation:
"Type mismatch: cannot convert from String to Document"
The context is this: I need to upload a JSON file with the following schema (note that the array "data" will contain up to 500 elements):
{
 "data":
}
I was unable to get the tWriteJSON field component to format the array correctly, so I was using that to define the subdocument, then passing that into tDenormalize & tMap to generate a string containing the full, correctly formatted JSON.
However, I need to sent this to a REST API, but the tRESTClient component seems to expect a document type. How can I convert my string to a document?
Labels (4)
1 Solution

Accepted Solutions
Anonymous
Not applicable
Author

Send the JSON string to the "string" input and not the "body" of the tRestClient. JSON is not a Document.

View solution in original post

19 Replies
Anonymous
Not applicable
Author

Send the JSON string to the "string" input and not the "body" of the tRestClient. JSON is not a Document.
Anonymous
Not applicable
Author

Thanks, this seems to have worked.
Mahboob
Contributor
Contributor

@rhall suggestion worked for me. thanks.

LuciusHunt
Contributor
Contributor

This works for me:

tFixedFlowInput -> tXMLMap -> tRESTClient

 

0693p000009SX45AAG.png

0693p000009SX4ZAAW.png

And be aware: Never press "Sync Columns" when you have a tRESTClient Component nearby! This destroys the schema of the tRESTClient and you have to replace it with a new one!

 

tRestClient: Set Content Type to JSON and in Advance Settings make sure "Drop JSON Request Root" is selected!

 

sam2000
Contributor II
Contributor II

Thanks @Holger Damczyk​  for the descriptive answer. It worked for me.

Reda_Sdn
Contributor
Contributor

Hi @Richard Hall​ ,

I tried your solution, it works for me but I have a problem when the request sent in the body is too long (more than 4050 characters) the trestClient does nothing and returns an empty response.

 

thanks in advance

Reda

 

Anonymous
Not applicable
Author

Hi @Reda Saidani​ ,

 

Are you saying that when you send a JSON String to the "string" input column of the tRestClient it fails if it is larger than 4050 characters? Or are you saying that it fails if the URL is greater than 4050 characters? I've never seen either of these limitations, but I may not have tested them. So I'd like to try this to see.

Reda_Sdn
Contributor
Contributor

when my String is less than 4050 characters it's work and i get the response but if it's greater than 4050 i have un empty response and any message and nothing happen in the API 0695b00000RhRA2AAN.png0695b00000RhRAHAA3.png0695b00000RhRACAA3.png0695b00000RhRA7AAN.png 

Reda_Sdn
Contributor
Contributor

this is the response for the 2 query 0695b00000RhRB5AAN.png 

response just for 1 query wich is less than 4050 characters