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 body field is the input. The default variable is message, so the input to convert is message.body.
  • The variable in the API context to store the conversion results. The conversion results are written to the body field 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 message as 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 also message. Therefore, if the input variable is foo, the output variable is also foo.
    • When you use an output variable other than message, the content is converted but not returned to the client.
  • 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

  1. In the search field, enter json.
  2. From the search results, click JSON to XML assembly action.
  3. Click Add.
  4. 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.
  5. Specify the conversion type.
  6. Specify the variable in the API context that contains the input message to convert.
  7. Specify the variable in the API context to store the conversion results.
  8. Specify the name of the root element.
  9. Specify whether the action always includes the root element that wraps the resulting XML document.
  10. Specify the name of the XML element that is the result of converting JSON array values to an XML format.
  11. Click Apply to save changes to the running configuration.
  12. Click Save to save changes to the persisted configuration.