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 your OpenAPI source; for details on how to configure the policy in the assembly user interface, see XML to JSON.
About
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.Properties
The following table describes the 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 |
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. |
string |
conversionType | No | The conversion type that determines the target format of the output. The following options are available:
|
string |
Example
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