DataPower Gateway only

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

Restriction: The XML to JSON policy can be used only with the DataPower® Gateway.

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.

You can attach this policy to the following API flows:
  • REST
  • SOAP

Use the API Designer 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.

Table 1. Policy properties
Property label Required Description Data type
Title Yes The title of the policy.

The default value is xml-to-json.

string
Description No A description of the policy. string

Examples

For example, the following simple XML object
<a>hello</a>
becomes
{ "a": { "$" : "hello" } }
The following XML object with an attribute
<a type="world">hello</a>
becomes
{ "a": { "$" : "hello", "@type" : "world" } }