Use the json-to-xml policy to convert the context payload of your API from the JavaScript Object Notation (JSON) format to the extensible markup language (XML) format.

Gateway support

Table 1. Table showing which gateways support this policy, and the corresponding policy version
Gateway Policy version
DataPower® Gateway (v5 compatible) 1.0.0
DataPower API Gateway 2.0.0

This topic describes how to configure the policy in your OpenAPI source; for details on how to configure the policy in the assembly user interface, see JSON to XML.


The json-to-xml policy has the following structure:
- json-to-xml:
   version: version
   title: Title
   description: Description
Note: If you are using the DataPower API Gateway, the input to the json-to-xml policy must be parsed data. One way to produce parsed data is to use a parse policy before a json-to-xml policy in your assembly flow, which provides explicit control of the parse action.


The following table describes the policy properties:
Table 2. Policy properties
Property Required Description Data type
version Yes The policy version number string
title Yes The title of the policy. string
description No A description of the policy. string
DataPower API Gateway
onlyinput 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
DataPower API Gateway
onlyoutput 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.

DataPower API Gateway
onlyconversionType 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-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-root-element property is set to true.  
always-output-root-element Yes Select this property to true you always want the policy to output the root element, even if it is not required to make the XML document well formed. boolean
unnamed-element-name No The XML element name to be used for JSON array elements. string


The following is an example of a json-to-xml policy:
- json-to-xml:
   version: 1.0.0
   title: JSON to XML transform
   description: Transforms JSON message body to XML format