| title | Azure API Management policy reference - xml-to-json | Microsoft Docs |
|---|---|
| description | Reference for the xml-to-json policy available for use in Azure API Management. Provides policy usage, settings, and examples. |
| services | api-management |
| author | dlepow |
| ms.service | azure-api-management |
| ms.topic | reference |
| ms.date | 09/06/2024 |
| ms.author | danlep |
[!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]
<xml-to-json kind="javascript-friendly | direct" apply="always | content-type-xml" consider-accept-header="true | false" always-array-child-elements="true | false"/>| 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 |
- Policy sections: inbound, outbound, on-error
- Policy scopes: global, workspace, product, API, operation
- Gateways: classic, v2, consumption, self-hosted, workspace
<policies>
<inbound>
<base />
</inbound>
<outbound>
<base />
<xml-to-json kind="direct" apply="always" consider-accept-header="false" />
</outbound>
</policies>[!INCLUDE api-management-policy-ref-next-steps]