The JSONiq data model

Table of Contents


JSONiq is a query language that was specifically designed for querying JSON, although its data model is powerful enough to handle more similar formats.

As stated on, JSON is a "lightweight data-interchange format. It is easy for humans to read and write. It is easy for machines to parse and generate."

A JSON document is made of the following building blocks: objects, arrays, strings, numbers, booleans and nulls.

JSONiq manipulates sequences of these building blocks, which are called items. Hence, a JSONiq value is a sequence of items.

Any JSONiq expression takes and returns sequences of items.

Comma-separated JSON-like building blocks is all you need to begin building your own sequences. You can mix and match, as JSONiq supports heterogeneous sequences seamlessly.

Example 1. A sequence

"foo", 2, true, { "foo", "bar" }, null, [ 1, 2, 3 ]

Result: foo 2 true foo bar null [ 1, 2, 3 ]

Sequences are flat and cannot be nested. This makes streaming possible, which is very powerful.

Example 2. Sequences are flat

( ("foo", 2), ( (true, 4, null), 6 ) )

Result: foo 2 true 4 null 6

A sequence can be empty. The empty sequence can be constructed with empty parentheses.

Example 3. The empty sequence



A sequence of just one item is considered the same as just this item. Whenever we say that an expression returns or takes one item, we really mean that it takes a singleton sequence of one item.

Example 4. A sequence of one item


Result: foo

JSONiq classifies the items mentioned above in three categories:

The JSONiq data model follows the W3C specification, but (in core JSONiq) does not include XML nodes, and includes instead JSON objects and arrays.