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

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 XML to JSON.


The xml-to-json policy has the following structure:
- xml-to-json:
   version: version
   title: Title
   description: Description
Note: If you are using the DataPower API Gateway, the input to the xml-to-json policy must be parsed data. One way to produce parsed data is to use a parse policy before an xml-to-json 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:
  • badgerFish: BadgerFish convention is used to determine the target conversion format of the output.
  • apicv5: apicv5 convention is used to determine the target conversion format of the output.


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