Convert Response from SOAP XML to JSON

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