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 30 years of relational query systems and more than 15 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.


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 Book

JSONiq - The SQL of NoSQL

Ghislain Fourny


JSONiq is a query and processing language specifically designed for the popular JSON data model. The main ideas behind JSONiq are based on lessons learned in more than 30 years of relational query systems and more than 15 years of experience with designing and implementing query languages for semi-structured data. As a result, JSONiq is an expressive and highly optimizable language to query and update any kind of JSONiq store or resource. It enables developers to leverage the same productive high-level language across a variety of NoSQL products. This book gives a complete introduction to the JSONiq language. It does so by giving examples for all types of expressions and functions. Those examples can be immediately used because they work standalone, which allows the interested reader to start diving into the language.

The electronic version of this book is available for free.

Get Free Electronic Version

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.