Converting JSON Message to XML Message

Using the northbound forward mapper, parse the JSON encoded string to generate an XML message. Usually, the JSON data is encoded using base64 format, therefore, the data must be converted from base64 to text. TIBCO API Exchange Gateway provides the codecs:base64ToText() function to convert the json data to text.

To parse a JSON encoded string in a north-side forward mapper, follow these steps:

Procedure

  1. Create an XSLT File.

    To create an XSLT file to parse the JSON encoded, perform the following steps:

    • Add namespaces:

      The parse() function requires the following namespaces: http://www.tibco.com/asg/functions/json

      http://www.tibco.com/asg/functions/codecs
    • Use the parse() function as follows:
      • Extract the base64 encoded request payload from the context document.
      • Use the codecs:base64ToText() function to convert the payload to text message.
      • Pass the text message to the json:parse() function.

    See Example XSLT to Convert BookQueryBE JSON Request to XML Request for an example XSLT.

  2. Upload the XSLT File.

    Using the Config UI, upload the XSLT file in the northbound forward mapper to parse the JSON encoded request message in XML message format as follows:

    1. Start the GUI server, if not already running.
    2. Log in to the Config UI using your credentials.
    3. Add a new project or select an existing project under Projects. For example, select the BookQueryBE project.
    4. Add the mapping configuration as follows:
      1. Click the MAPPING > Mapping tab.
      2. Click the Add property to create a new mapping.
      3. Enter the parameters, as follows:
      • Mapping Name: JSON_XML_Mapping.
      • Type: XSLT (select from the drop-down list.).
      • New File: Click Choose File and select the XSLT file.
      • Response Type: Full (select from the drop-down list.)
      • Save the changes to your configuration.
    5. Select the mapper for the facade operation, as follows:
      1. Click the ROUTING > Facade Operations tab.
      2. Select the facade operation.
      3. In the Request Transform field, select JSON_XML_Mapping mapper, as created in the mapping configuration from the drop-down list.
      4. Save the changes to your configuration.