BT
x Your opinion matters! Please fill in the InfoQ Survey about your reading habits!

JSONiq: The JSON Query Language

by Jonathan Allen on Oct 08, 2012 |

JSONiq is a new query language that builds upon XQuery. Like SQL or LINQ, it has syntactic support concepts such as let, for, where, group by, and select. Here is an example:

let $stats := db:find("stats")
for $access in $stats
where $access("response_time") > 5
group by $url := $access("url")
return
{
    "url": $url,
    "avg": avg($access("response_time")),
    "hits": count($access)
}

JSONiq supports than just JSON to JSON transformations. You can use it to generate or parse XML and even create queries that merge the two. In this example from the documentation, you can see JSONiq being used as a template language to generate HTML tables.

Like XQuery, JSONiq supports overlapping and non-overlapping windows. This feature is used for breaking data into evenly sized chunks or for statistical calculations such as “last 3” averages. You can learn more about tumbling and sliding windows in the XPath specification.

Another feature of JSONiq is the ability to update JSON data. In this example, you can see a status property being inserted into records that match the name "Deadbeat Jim".

JSONiq is available as part of the XQuery processor Zorba, which is distributed under Apache 2 License. JSONiq itself is licensed under the Creative Commons Attribution-ShareAlike 3.0 Unported License.

Hello stranger!

You need to Register an InfoQ account or or login to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Tell us what you think

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

MongoDB driver by William Candillon

A mongodb driver has already been implemented on top of JSONiq.
You can try it live at 28.io/mongodb

Looks somewhat like XQuery by Faisal Waris

the syntax closely resembles XQuery - the language for querying xml documents

en.wikipedia.org/wiki/XQuery

Theoretically, How does this differ from Ember.js query model? by Guy Ndjeng

Pretty cool!!
Technically I think it's a good initiative but in theory, how does this differ from Larger JS framework like Ember.js which provides a JSON query model that developers have adopted? The other question is how does this play with others?
Moreover, I am hearing that ECMAScript 5 will have an inherent mechanism for querying Javascript Objects which should address this problem..

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

3 Discuss

Educational Content

General Feedback
Bugs
Advertising
Editorial
InfoQ.com and all content copyright © 2006-2014 C4Media Inc. InfoQ.com hosted at Contegix, the best ISP we've ever worked with.
Privacy policy
BT