Edit online

Transforming JSON Documents with XSLT

There are several methods that can be used to transform JSON documents through XSLT processing.

Transforming a JSON Document Directly with XSLT

  1. Create a new transformation scenario using one of the following types of transformations:
  2. Configure the transformation scenario to suit your needs. In the XSLT tab, make sure you select the JSON file in the JSON URL field and the XSL file in the XSL URL field.
  3. Run the transformation.

Transforming Multiple JSON Documents at Once

It is also possible to transform multiple JSON documents at once with XSLT processing. To achieve this, select the JSON documents in the Project view, right-click, and apply or configure a transformation scenario.

Transforming a JSON Document Using XSLT and XPath Functions

  1. Create an XSLT 3.0 stylesheet that has the xsl:initial-template. You can use one of the following two templates available in the New Document Wizard.
    • XSLT Stylesheet for JSON - Processes a JSON document by using a json-doc() function and matches the JSON properties from the JSON map.
    • XSLT Stylesheet for JSON to XML - Processes a JSON document by using a json-to-xml() function and matches the converted XML content.
  2. Create a new XSLT transformation scenario for your stylesheet.
  3. Reference the JSON document that you want to transform using one of these two methods:
    • In the transformation scenario, click the Parameters button in the XSLT tab and add a parameter that specifies the URL to your JSON document in its value. For example, if you are transforming one of the built-in templates mentioned above, the input parameter is added by default and you could specify the URL in its value.
    • Specify the URL to your JSON document in the stylesheet you created. For example, if you use one of the built-in templates mentioned above, you would specify the URL in the value of the input parameter (in the xsl:param element).
  4. Run the transformation.
Tip: There are some sample files in the [OXYGEN_INSTALL_DIR]/samples/json/transform folder that can be used to transform a JSON document to XML or HTML.