XML to JSON
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
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 the assembly user interface; for details on how to configure the policy in your OpenAPI source, see xml-to-json.
About
The XML to JSON policy uses a simple convention, based on BadgerFish, to convert your API context payload from XML to JSON. The XML content is preserved, including the attributes and namespaces. No additional configuration is required. For more information about the BadgerFish convention, including some examples, see BadgerFish.
- REST
- SOAP
Use the API Manager assembly view when you are creating your API definition to add a built-in policy to the flow.
The policy must be attached to the flow at the point at which you require the conversion to be performed. For example, if you need to convert an XML-formatted request into a JSON-formatted request, the policy must be attached to the request flow.
The policy reads input from the message.body
, if that context exists, otherwise
from the request.body
, and then writes the output to the
message.body
.
Properties
The following table lists the policy properties, indicates whether a property is required, specifies the valid and default values for input, and specifies the data type of the values.
Property label | Required | Description | Data type |
---|---|---|---|
Title | Yes | The title of the policy. The default value is |
string |
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 XML 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 XML format to JSON 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. |
string |
Conversion type | No | The conversion type that determines the target format of the output. The following options are available:
|
string |
Examples
<a>hello</a>
becomes{ "a": { "$" : "hello" } }
<a type="world">hello</a>
becomes{ "a": { "$" : "hello", "@type" : "world" } }