Convert Response from SOAP XML to JSON

I have a soap API with Rest Transformation.
when I call the API as json the request is sent as JSON but the response is returned as XML.
how to convert the XML to Json using response transformation policy just when the request is json?

hi @mahmoud_elarabi,
We can write xslt in response transformation policy to achieve same.
You can refer below link for it

Regards
Vikash Sharma

Proceed with caution. There are representations in XML that cannot be accurately converted to JSON without additional definition such as an XSD. E.g. In XML, an array of elements is obvious when there are >1 entries in the list. But if there is just 1 entry, it cannot be determined from the XML alone that the single element should be placed in an array.

Avoid this if possible. Depending upon the data what you may face is “this mostly works but then occasionally it returns ‘bad’ data” because an element that should be in [ ] is not.

Check with the API to see if honors the Accept header and have the caller specify Accept: application/json so that the API itself returns JSON and your components do not need to translate.

Edit: If you’re using API GW, it has it’s own translation facility (with same caveat as above). No need to introduce another component.

Edit2: Might find the info in this thread WM API Gateway - Request Transformation Payload - From JSON to XML? helpful.

2 Likes

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.