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.

Note

Set a policy's elements and child elements in the order provided in the policy statement. Learn more about how to set or edit API Management policies.

Policy statement

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

Attributes

Attribute 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.

Policy expressions are allowed.
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.

Policy expressions are allowed.
Yes N/A
consider-accept-header The attribute must be set to one of the following values.

- true - apply conversion if JSON is requested in request Accept header.
- false -always apply conversion.

Policy expressions are allowed.
No true

Usage

Example

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

Next steps

For more information about working with policies, see: