Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
A IBM Datapower gateway script to convert XML to JSON
Gatewayscript file for IBM Datapower
This file converts XML to JSON using Datapowers builtin "json-xml-converter module" (Firmware 7.5.0 and Above)
Example Datapower flow using MPGW:
Client -> Convert Query Params to XML -> *this gatewayscript file* -> Parse Action (Object Reference set to JSON) -> Validate using JSON Schema -> Server
*Note: Output JSON is in "BadgerFish" Format*
Helpfull Links:
Created by Thomas Cope
var converter = require('json-xml-converter');
var hm = require('header-metadata');
session.input.readAsXML(function (error, xml) {
if (error) {
session.reject("Document contains Invalid XML. Can not convert XML to JSON with Invalid XML.");
var xmlString = XML.stringify(xml);
var xmlDOM = XML.parse(xmlString);
console.debug("Converting XML to JSON");
var json = converter.toJSON("badgerfish", xmlDOM)
var headers = hm.current;
headers.set('Content-Type', 'application/json');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment