Skip to main content
Announcements
July 15, NEW Customer Portal: Initial launch will improve how you submit Support Cases. IMPORTANT DETAILS
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

How to allow user to select JSON or XML response from tRESTRequest

Can anyone explain to me how to get the tRESTRequest component to allow the user to specify whether to return either JSON or XML?  I can get my service to return JSON by setting "Produces=JSON" and it returns XML by setting "Produces=XML".  However, when I set "Produces=XML or JSON", I am only able to get XML response.
I should add that I am accessing this from my browser (Chrome).  So for example, I am going to http://localhost:8088/customers and I would like to know whether it is possible to add something to the end of that URL which would tell the service whether to return XML or JSON.  Is it possible to do this through the URL?
Thanks.
Labels (5)
4 Replies
Anonymous
Not applicable
Author

Hi 
If you use tRestClient to call the webservice  and select Accept type as 'JSON' on tRestClient, it will return json response.
ID: 1
Response-Code: 200
Encoding: ISO-8859-1
Content-Type: application/json
Headers: {content-type=, Date=, Server=, transfer-encoding=}
Payload: {"root":{"person":}}


Best regards
Shong
Anonymous
Not applicable
Author

Shong,
I tried your suggestion but it does not appear to be working as expected.  I selected "JSON" form the "Accept Type" dropdown and I still get XML.  I also set the header of "Accept" and "application/json" and I still get XML.  Next, I discovered that if you set the value of "Accept Type" to "Any" and specify a header of "Accept" = "application/json", then you get JSON, but you can't get JSON if you select "JSON" from the dropdown.
I have attached screenshots showing the following:
1. Select "Accept Type=JSON" and set header of "Accept = application/json".  Output is XML.
2. Change "Accept Type=Any" and leave the same header.  Output is JSON.
Am I doing something wrong that is causing me to be unable to get JSON output when I select JSON from the dropdown?
0683p000009MB46.png 0683p000009MAag.png 0683p000009MArr.png

0683p000009MB4B.png 0683p000009MB4G.png
Anonymous
Not applicable
Author

I have the same issue, Did you got any solution for this. I have also set to accept and and Accept header as JSON but all I'm getting is an xml result

Gwyn
Contributor
Contributor

I’m working on the same now where the output is always xml even when I specify the accept type as JSON. Is there are solution to this?