Page 1 of 1

Querying JSON the XPath 3.1 way

Posted: Sat Apr 20, 2019 10:25 am
by Martin Honnen
In https://www.oxygenxml.com/doc/versions/ ... rming.html, it is explained how to use XSLT or XQuery to transform JSON input and https://www.oxygenxml.com/doc/versions/ ... query.html explains how to use "XPath" to select data from a JSON document.

To my suprise, these topics seem to use completely different approaches as the "XPath" expressions used to select data from a JSON file seem to rely on an oXygen internal JSON to XML conversion and query that XML while the samples on XSLT and XQuery use the XPath 3.1 way of representing JSON as maps and arrays.

I would like to see a way to use the XPath toolbar with expression completion against a JSON document supporting the XPath 3.1 syntax (e.g.

Code: Select all

?personnel?person?*[?link?manager = "Big.Boss"]?name?given
It would also be nice to have the "copy XPath" menu to allow generating such XPath 3.1 expressions.

Re: Querying JSON the XPath 3.1 way

Posted: Mon Apr 22, 2019 9:14 am
by tavy
Hello Martin.

Thanks for your feedback.
We decided to implement the XPath support for JSON by converting the JSON documents to XML and then execute the XPath over the XML documents. The JSON to XML conversion is based on the "json.org" library, is the standard JSON to XML conversion. By executing the XPath over the converted XML document you will benefit of full XPath support, for example you can use "ancestor::". "parent::", or "preceding::" axes, otherwise you will be limited and you will not benefit of the full XPath support.
It would be interesting to make the XPath support for JSON documents to work also with XPath 3.1 map/array lookup operator, as you mentioned. I think this would be better for those who are developing XQuery or XSLT for processing JSON documents. I would add an issue to analyze this support better.

Best Regards,
Octavian