Returning JSON from a JEE (Workbench) Process

When creating Adaptive Forms you are likely looking to return JSON rather than XML. It is much easier to parse than XML and there are just so many tools out there to parse JSON today making the move to JSON is just a logical thing to do.

First off, full credit for this article has to go to @bojanbjelic. His XSLT is key to turning your XML into JSON in record time: https://github.com/bojanbjelic/xml2json/ Optionally you could create your own custom DSC and convert XML to JSON using a multitude of Java options.

To convert your existing XML into a JSON response you simply need to add the XSLT step to the end of your process before your output is returned. Additionally, you’ll need to output a lengthy String instead of an XML variable.

  • Drag and drop the “XSLT Transformation – 1.0 – transform” service to the end of XMLToXSLTInJEEyour process.
  • In the “Source XML document” specify the xml document you’d like to transform to JSON.
  • Open the XSLT window:
    • In the XSLT tab, provide the XSLT from Bojan.
    • In the Text XML, provide a sample of the data you want to transform. Note that this should be a small example. When exporting your server process configuration, this test xml will be included in the export making it larger than necessary.
    • In the Test Result, click “Test” to ensure your conversion takes place.
  • In the “Transformed XML” select your String output variable. This needs to be large enough to handle your data on each occurrence. Select “unlimited” for the size if necessary.

Your process(es) will now provide you with JSON output instead of XML. Ideally you can create a second service with a JSON suffix that calls your original service, but returns JSON allowing you to continue to support both XML and JSON without creating another full process.