Project

Profile

Help

Direct XQuery of JSON Messages?

Added by Ken Beitel almost 3 years ago

Hello Michael,

I have a question as to whether the Saxon API supports direct XQuery of JSON messages or whether the JSON first needs to be converted to XML. If yes, would it be possible to get a sample code tidbit to show usage?

If not, for down the road, the XQuery 3.1 spec indicates that JSON can losslessly be converted to an XDM so that XQuery can be used.

If this capability is not yet offered in the Saxon API, are there plans to add this to a near future release?

Thanks - Ken


Replies (2)

RE: Direct XQuery of JSON Messages? - Added by Michael Kay almost 3 years ago

There are two ways of handling JSON in XSLT 3.0 / XQuery 3.1:

  • You can convert it to XML using the json-to-xml() function, and then process the XML

  • you can convert it to maps-and-arrays using the parse-json() function, and then process the maps and arrays.

Both solutions are workable and both are implemented in Saxon.

I compared the two approaches (for XSLT rather than XQuery) in a conference paper:

http://www.saxonica.com/papers/xmlprague-2016mhk.pdf

There are a couple of examples in that paper but on the whole, to use this tooling I think you're going to have to read the W3C specs.

RE: Direct XQuery of JSON Messages? - Added by Ken Beitel almost 3 years ago

Thanks Michael - the fast response has been most helpful.

    (1-2/2)

    Please register to reply