- Syvizo API Management Platform
- Overview
- Getting Started
- Manage Users and Accesses
- Design APIs
- Publish API
- Collaborate
- Validate APIs
- Manage API Flows
- Flow Management
- API Flow Manager
- Policies
- Traffic Management
- Security
- Transformation
- Extension
- Insights
XML to JSON
When to use
Use this policy when you want to transform messages from XML format to JSON format
Details
The XML to JSON policy allows for the conversion of messages from the XML format to JSON format. It provides various options to control and customize the conversion process.
To convert an XML-formatted response into a JSON-formatted response, you would typically attach the XML to JSON policy to the response flow, such as Response/ProxyEndpoint/PostFlow. This ensures that the conversion takes place during the response phase.
In a typical mediation scenario, you might pair a JSON to XML policy on the inbound request flow with an XML to JSON policy on the outbound response flow. This allows you to expose a JSON API for backend services that primarily support XML natively. By combining these policies, you can bridge the gap between XML-based backend services and clients expecting JSON responses.
Additionally, when APIs are consumed by diverse client applications that may require either JSON or XML, you can dynamically set the response format. This can be achieved by configuring the JSON to XML and XML to JSON policies to execute conditionally based on specific criteria. For more information on implementing this scenario, you can refer to the documentation on flow variables and conditions.
By utilizing the XML to JSON policy in conjunction with other policies, you can effectively convert XML messages to JSON format, enabling interoperability and flexibility in your API responses.
Configuration
The configuration fields for the policy are:
[* Indicates a mandatory field]
Name *: Display name of the policy
Description: Description of policy
Enabled: Flag to indicate if the policy is enabled. If this field is not checked, the policy will be ignored at runtime and any fields from its output will contain a default initial value
Continue on Error: Flag to indicate that the flow should continue even if this policy throws an error
Keep Numbers: If this is checked, then the numbers in XML will be retained as numbers
Keep Boolean: If this is checked, then the boolean values (true and false) in XML will be retained as numbers
Empty As Null: If this is checked, then the empty values in XML will be converted to empty strings, otherwise they will be converted to null
Namespace Object: The namespaces will be put in an object with this name in json
Default Namespace Property: The default namespace will be assigned as value to a property with this name
Namespace Separator: Namespace separator in XML will be converted to this string in json object
Prefix: If this is specified, then the object body will be prepended with the value specified in this
Suffix: If this is specified, then the object body will be appended with the value specified in this
Text To Property: If this is set to true, the text in XML element will be created as property with name as specified in the configuration value “Text Property Name”
Text Property Name: If “Text To Property” configuration is set to true, then text in XML element will be created as property with name as specified in this field
Attribute Object Name: The attributes in XML will be put as properties in object with this name
Attribute Prefix: The attributes names in XML will be put in the object with name specified in configuration field “” and value specified in this field will be added as suffix to object property
Array Element Name: The element names specified in this will be converted as json array. The element names must be specified as complete path in xml. For example in to specify employees as array in following example, specify Organization/department/employees
< Organization>
<department>
<employees>
<name>Alex</name>
<name>Sandy</name>
<name>Deborah</name>
<employees>
<department>
< Organization>
Input fields
source: The XML string which should be converted to json
Output fields
jsonString: Resulting XML string after transformation