Skip to content

Latest commit

 

History

History
61 lines (44 loc) · 3.01 KB

xml-to-json-policy.md

File metadata and controls

61 lines (44 loc) · 3.01 KB
title description services author ms.service ms.topic ms.date ms.author
Azure API Management policy reference - xml-to-json | Microsoft Docs
Reference for the xml-to-json policy available for use in Azure API Management. Provides policy usage, settings, and examples.
api-management
dlepow
azure-api-management
reference
09/06/2024
danlep

Convert XML to JSON

[!INCLUDE api-management-availability-all-tiers]

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.

[!INCLUDE api-management-policy-generic-alert]

Policy statement

<xml-to-json kind="javascript-friendly | direct" apply="always | content-type-xml" consider-accept-header="true | false" always-array-child-elements="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
always-array-child-elements The attribute must be set to one of the following values.

- true - Always convert child elements into a JSON array.
- false - Only convert multiple child elements into a JSON array. Convert a single child element into a JSON object.

Policy expressions are allowed.
No false

Usage

Example

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

Related policies

[!INCLUDE api-management-policy-ref-next-steps]