DataPower API Gateway

Configuring the JSON to XML policy for DataPower API Gateway

Follow these steps to configure the JSON to XML policy for DataPower® API Gateway in the assembly user interface.

About this task

Note: This topic describes the JSON to XML policy implementation in the DataPower API Gateway. If you are using the DataPower Gateway (v5 compatible), see Configuring the JSON to XML policy for DataPower Gateway (v5 compatible). For more information about the different types of gateway, see API Connect gateway types.

For information about how to configure the policy in your OpenAPI source, see json-to-xml.


  1. In the navigation pane, click Develop icon in the navigation pane Develop, then select the APIs tab.
    The Develop page opens.
  2. Click the title of the API definition that you want to work with, or create a new API.
  3. Select the Gateway tab, then click Policies in the navigation pane.
    For more information about working with the assembly editor for an API, see The assembly editor.
  4. Find the JSON to XML policy in the palette, and drag the policy onto your canvas.
  5. Specify the following properties.
    Table 1. Policy properties
    Property label Required Description Data type
    Title Yes The title of the policy.

    The default value is json-to-xml.

    Description No A description of the policy. string
    Input No The input message to convert. Specify the name of a variable in the API context. variableName.body, the message payload, represents the JSON input to convert. The default value of the variable is message and message.body is the default input. string
    Output No The output message to store the conversion result. Specify the name of a variable in the API context. variableName.body represents the result of conversion from JSON format to XML format. When the specified input message is the default message, the default output is message.body. Otherwise, when the input message is the variable my-message-variable, for example, the default output is my-message-variable.body.

    The variable cannot be any read-only in the API context.

    Conversion type No The conversion type that determines the target format of the output. The following options are available:
    • None: No conversion of the output takes place.
    • badgerFish: BadgerFish convention is used to determine the target conversion format of the output.
    Root XML Element Name Yes The root element name of the resultant XML document. This property is used only if the input JSON document is not hierarchical and has more than one uppermost level property, or if the Always output the root element checkbox is selected.

    The default value is json.

    Always output the root element Yes Select this checkbox if you always want the policy to output the root element, even if it is not required to make the XML document well formed.

    The default value is false.

    Element name for JSON array elements No The XML element name to be used for JSON array elements. string
  6. Specify a version for the policy by clicking the Source icon OpenAPI Source icon, and completing the version section of the policy YAML. For example:
      - json-to-xml:
          version: 2.0.0
          title: json-to-xml
    You must specify a version for the policy that is compatible with the gateway that you are using. When the API is published, if the version is incompatible with the gateway, a validation error is thrown that specifies the available versions.
  7. Click Save.


For example, the following simple JSON object
{ "a": { "$" : "hello" } }
The following JSON object with an attribute
{ "a": { "$" : "hello", "@type" : "world" } }
<a type="world">hello</a>