json-to-xml
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
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.
About
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.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 |
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 |
Example
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