Adding a JSON to XML assembly action for payload format conversion
A JSON to XML assembly action converts the payload of an API message from JSON format to the equivalent XML format.
About this task
In a JSON to XML assembly action, you define the following settings.
- The conversion type that determines the target format of the XML output. The following types are supported.
- BadgerFish
- Converts the input to XML with the BadgerFish convention.
- Relaxed BadgerFish
- Converts the input to XML with the BadgerFish convention and special conversion rules for broader compatibility with non-BadgerFish input. These rules include the conversion of plain JSON to XML.
- The variable in the API context that contains the input message to convert. The
content of the
bodyfield is the input. The default variable ismessage, so the input to convert ismessage.body. - The variable in the API context to store the conversion results. The conversion
results are written to the
bodyfield of the specified variable. The output variable cannot be a read-only variable.- When you want the converted output to be returned to the client, you must use
messageas the output variable. - When you do not specify an output variable, the variable name matches the input variable name.
For example, if the input variable is
message, the output variable is alsomessage. Therefore, if the input variable isfoo, the output variable is alsofoo. - When you use an output variable other than
message, the content is converted but not returned to the client.
- When you want the converted output to be returned to the client, you must use
- When the action is to always include the root element, specify the root element to include when
the JSON input does not have a root object. The default name is
json. - Decide whether the action always includes the root element that wraps the resulting XML document. By default, this action does not always include the root element.
- The name of the XML element that is the result of converting JSON array values to an XML format.
Procedure
- In the search field, enter json.
- From the search results, click JSON to XML assembly action.
- Click Add.
- Define the basic properties: Name, administrative state, descriptive summary,
title, and correlation path. The correlation path indicates the part of the API definition that correlates with the assembly action. This path is included in the debug data for use by debugging tools. For example, when an API configuration is specified in an OpenAPI document with gateway extensions, this path is the JSON path to the policy in the IBM extensions section of the document. The path can be expressed in any form that the debugging tool can correlate to the API definition.
- Specify the conversion type.
- Specify the variable in the API context that contains the input message to convert.
- Specify the variable in the API context to store the conversion results.
- Specify the name of the root element.
- Specify whether the action always includes the root element that wraps the resulting XML document.
- Specify the name of the XML element that is the result of converting JSON array values to an XML format.
- Click Apply to save changes to the running configuration.
- Click Save to save changes to the persisted configuration.