Follow these steps to configure the JSON to XML policy for DataPower® Gateway (v5 compatible) in the assembly
user interface.
About this task
For details on how to configure the policy in your OpenAPI source, see json-to-xml.
Procedure
-
In the navigation pane, click
Develop, then select the APIs tab.
The Develop page
opens.
-
Click the title of the API that you want to work with, or create a new API.
- Select the Gateway tab, then click
Policies in the navigation pane.
For more information about
working with the assembly editor for an API, see
The assembly editor.
- Find the JSON to XML policy in the palette, and drag the policy onto your canvas.
- Specify the following properties.
Table 1. Policy properties
Property label |
Required |
Description |
Data type |
Title |
Yes |
The title of the policy. The default value is json-to-xml .
|
string |
Description |
No |
A description of the policy. |
string |
Root XML 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 the root element checkbox is selected. The default value is
json .
|
string |
Always output the root element |
Yes |
Select this checkbox if you always want the policy to output the root element, even if it is
not required to make the XML document well formed. The default value is
false .
|
boolean |
Element name for JSON array elements |
No |
The XML element name to be used for JSON array elements. |
string |
- Specify a version for the policy by clicking the Source icon
,
and completing the
version
section of the policy YAML. For
example: execute:
- json-to-xml:
version: 1.0.0
title: json-to-xml
...
You must specify a version for the policy that is compatible with the gateway that
you are using. When the API is published, if the version is incompatible with the gateway, a
validation error is thrown that specifies the available versions.
- Click Save.
Example
For example, the following simple JSON
object
{ "a": { "$" : "hello" } }
becomes
<a>hello</a>
The following JSON object with an
attribute
{ "a": { "$" : "hello", "@type" : "world" } }
becomes
<a type="world">hello</a>