Converting XML Message to JSON Message
By default, TIBCO API Exchange Gateway sends the response message in XML format from the target operation to the client. If a client requests the response message in a JSON format, you can convert the XML message to a JSON message as follows:
- Procedure
- Create an XSLT File.
To create an XSLT file to render the data in JSON format, follow these high level steps:
Add namespaces:The
render()
function requires the following namespace:http://www.tibco.com/asg/functions/json
Build JSON structure.Use the render() function:See Example XSLT to Convert BookQuery XML Response to JSON Response for an example XSLT.
- Upload the XSLT File.
Using the Config UI, upload the XSLT file in the northbound reverse mapper to render the XML response message in JSON message format as follows:
- Start the GUI server, if not already running.
- Log in to the Config UI using your credentials.
- Add a new project or select an existing project under Projects. For example, select BookQuery project.
- Add the mapping configuration as follows:
- Click the tab.
- Click the Add property to create a new mapping.
- Enter the parameters, as follows:
- Mapping Name: XML_JSON_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.
- Select the mapper for the facade operation, as follows:
- Click the tab.
- Select the facade operation.
- In the Response Transform field, select the XML_JSON_Mapping mapper, as created in the mapping configuration from the drop-down list.
- Save the changes to your configuration.