XML, JSON, XSLT and XQuery

Part of Data

Author(s) and publish date

Skip to 6 comments

The XML work at W3C was rechartered this Summer until 2015, and new work includes adding some JSON support to XSLT and XQuery.

This is still work in progress, so the designs are not final: there are a lot of details to be worked out, not least because JSON and XML have some deep-rooted differences.

The biggest difference is social: JSON is often used in environments where programmers get to decide what format is used for data that their program will use. XML is often used where the same information is shared between many programs, possibly including some unknown programs, and where the data is owned by its creators, who are not necessarily programmers.

A consequence of this difference is that XML tends to be much harder for programmers to deal with than JSON, because it wasn't primarily designed for them.

But to the point here, JSON parsing and generation can be harder than it looks using XML tools, and we want to make it easy for the XML world to interoperate with JSON APIs and data.

There are two main approaches that make sense when integrating data formats:

  1. Convert the data at the system boundary;
  2. Extend the core to handle both types of data

The current XSLT 3 draft provdes a parse_json() function to turn JSON into a specific internal representation in its existing tree-based data model, and another function to take such a data model instance and turn it into JSON. Then you can use standard XSLT templates, XPath, functions and operators to process the JSON data.

XSLT 3 also adds a dictionary type (often called a "hash"); XSLT calls it a map. The map can be used to work in a more JavaScript/JSON way with key/value pairs. There are no arrays: you use a map with integer keys right now.

XQuery will also add the new map data type, and will probably add arrays. In the database environment where XQuery often lives it's not so easy to determine the proper relationship between the new data structures and the database, so that's ongoing.

The upshot will be that XSLT 3 and XQuery 3.1 will have access to JSON data, the ability to generate JSON, and also tools to work with JSON in a query or transformation.

Related RSS feed

Comments (6)

Comments for this post are closed.