JSONiq is a query language specifically designed for the popular JSON data model. The main ideas behind JSONiq are based on lessons learnt in more than 50 years of relational query systems and 30 years of experience with semi-structured data.
Every language construct in JSONiq is an expression; they are fully composable and the result of a query is the result of the evaluation of its main expression. Project, Select, Filter, Join, Group, Order... Like SQL, JSONiq can do all that.
Since most of its syntax, atomic types and builtin functions are directly based on a W3C standard, it makes a wide range of systems interoperable, just like SQL for relational systems. Unlike many language proposals for nested data, JSONiq has several independent implementations, is fully specified, maintained, supported, publicly documented, and available under a permissive Creative Commons license.
The JSONiq Data Model (JDM) is compatible with many JSON-like formats such as text, CSV, Parquet, making it interoperable. Any JSONiq value is a sequence of items, where an item can be an atomic value, an object, an array or a function item that can be called dynamically.
Unlike SQL, which can only manipulate normalized data, JSONiq natively works on the entire normalization spectrum: textual, heterogeneous, deeply nested. With JSONiq, you can denormalize and normalize your data at will thanks to the flexibility of sequences of items, with no compromise on performance.
Because of its flexible data model, JSONiq is well suited as a data lake language. JSONiq also enables developers to leverage the same productive high-level language across a variety of NoSQL products, including document stores with support for schemas, indices and updates.
As of 2022, the JSONiq specifications are stable and maintained and we actively offer support on StackOverflow.
Version 0.42 of the specification of the JSONiq extension to XQuery is kept online (although deprecated) as it is used in IBM WebSphere.
JSONiq has two brothers: Look at the TYSON syntax and JSound 2.0 schema specifications.
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.
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. }