Convert JSON to XML

APPLIES TO: All API Management tiers

The json-to-xml policy converts a request or response body from JSON to XML.


Set the 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

    apply="always | content-type-json" 
    consider-accept-header="true | false" 
    parse-date="true | false" 
    namespace-separator="separator character"
    namespace-prefix="namespace prefix"
    attribute-block-name="name" />


Attribute Description Required Default
apply The attribute must be set to one of the following values.

- always - always apply conversion.
- content-type-json - convert only if response Content-Type header indicates presence of JSON.

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 XML is requested in request Accept header.
- false - always apply conversion.

Policy expressions are allowed.
No true
parse-date When set to false date values are simply copied during transformation. Policy expressions aren't allowed. No true
namespace-separator The character to use as a namespace separator. Policy expressions are allowed. No Underscore
namespace-prefix The string that identifies property as namespace attribute, usually "xmlns". Properties with names beginning with specified prefix will be added to current element as namespace declarations. Policy expressions are allowed. No N/A
attribute-block-name When set, properties inside the named object will be added to the element as attributes. Policy expressions are allowed. No Not set



Consider the following policy:

        <base />
        <base />
        <json-to-xml apply="always" consider-accept-header="false" parse-date="false" namespace-separator=":" namespace-prefix="xmlns" attribute-block-name="#attrs" />

If the backend returns the following JSON:

  "soapenv:Envelope": {
    "xmlns:soapenv": "",
    "xmlns:v1": "",
    "soapenv:Header": {},
    "soapenv:Body": {
      "v1:QueryList": {
        "#attrs": {
          "queryName": "test"
        "v1:QueryItem": {
          "name": "dummy text"

The XML response to the client will be:

<soapenv:Envelope xmlns:soapenv="" xmlns:v1="">
  <soapenv:Header />
    <v1:QueryList queryName="test">
      <name>dummy text</name>

For more information about working with policies, see: