The JSON Query Language

Decades of Lessons Learnt

Decades of Lessons Learnt

JSONiq is a query and processing language specifically designed for the popular JSON data model. The main ideas behind JSONiq are based on lessons learnt in more than 40 years of relational query systems and more than 20 years of experience with designing and implementing query languages for semi-structured data.

Complex Processing

Complex Processing

A JSONiq program is an expression; the result of the program is the result of the evaluation of the expression. Expressions have fundamental role in the language: every language construct is an expression, and expressions are fully composable. Project, Filter, Join, Group... Like SQL, JSONiq can do all that.

The SQL of NoSQL

The SQL of NoSQL

JSOniq is an expressive and highly optimizable language to query and update NoSQL stores. It enables developers to leverage the same productive high-level language across a variety of NoSQL products.


As of 2017, the JSONiq specifications are stable and maintained. They have almost not changed since 2013, as version 1.0 was published.

Version 0.42 of the specification of the JSONiq extension to XQuery is kept online (although deprecated) as it is used in IBM Websphere.

The JSound schema language is stable as well, but should still be considered beta.

The Syntax

  1. let $stats := collection("stats")
  2. for $access in $stats
  3. group by $url := $access.url
  4. return
  5. {
  6. "url": $url,
  7. "avg": avg($access.response_time),
  8. "hits": count($access)
  9. }

Hint: hover over me.

The JSONiq syntax enables to dynamically construct objects and arrays using a syntax close to JSON. Nesting of expressions inside these constructors are allowed. JSONiq also provides a syntax for updating JSON objects and array.

The JSONiq Core Language

The main source of inspiration behind JSONiq is XQuery, which has been proven so far a successful and productive query language for semi-structured data (in particular XML). JSONiq borrowed a large numbers of ideas from XQuery, like the structure and semantics of a FLWOR construct, the functional aspect of the language, the semantics of comparisons in the face of data heterogeneity, the declarative, snapshot-based updates. However, unlike XQuery, JSONiq is not concerned with the peculiarities of XML, like mixed content, ordered children, the confusion between attributes and elements, the complexities of namespaces and QNames, or the complexities of XML Schema, and so on.

JSONiq Extension To XQuery

On this Web site, you will also find an extension, based on JSONiq, which adds JSON support to XQuery. The JSONiq extension to XQuery allows processing XML and JSON natively and with a single language. This extension is based on the same data model as the core JSONiq and is based on the same logical concepts. Because of the complexity of the XQuery grammar, the JSONiq extension to XQuery has a less pleasant syntax. For example, object lookup is done with a function invocation syntax, all keys must be quoted, and escaping is done with ampersands instead of backslashes, builtin atomic types must be prefixed with xs:, true, false and null must be created with functions, structured item types must be followed by parentheses.