Convert XML to JSON
The xml-to-json policy converts a request or response body from XML to JSON. This policy can be used to modernize APIs based on XML-only backend web services.

Policy statement

XML
<xml-to-json kind="javascript-friendly | direct" apply="always | content-type-xml" consider-accept-header="true | false"/>

Example

XML
<policies>
<inbound>
<base />
</inbound>
<outbound>
<base />
<xml-to-json kind="direct" apply="always" consider-accept-header="false" />
</outbound>
</policies>

Elements

Name
Description
Required
xml-to-json
Root element
Yes

Attributes

Name
Description
Required
Default
kind
The attribute must be set to one of the following values:
  • javascript-friendly – the converted JSON has a form friendly to JavaScript developers,
  • direct – the converted JSON reflects the original XML document's structure.
Yes
N/A
apply
The attribute must be set to one of the following values:
  • always – convert always.
  • content-type-xml – convert only if response Content-Type header indicates presence of XML.
Yes
N/A
consider-accept-header
The attribute must be set to one of the following values:
  • true – apply conversion if XML is requested in request Accept header,
  • false – always apply conversion.
No
true

Usage

This policy can be used in the inbound, outbound, and on-error policy scopes.
Questions? We're always happy to help with any issues you might have! Send us an email to [email protected] or request the demo with our sales team!
Copy link
On this page
Policy statement
Example
Elements
Attributes
Usage