BT

Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ

Topics

Choose your language

InfoQ Homepage News JSONiq: The JSON Query Language

JSONiq: The JSON Query Language

Leia em Português

This item in japanese

Bookmarks

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.

Rate this Article

Adoption
Style

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.

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

Community comments

  • MongoDB driver

    by William Candillon,

    Your message is awaiting moderation. Thank you for participating in the discussion.

    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,

    Your message is awaiting moderation. Thank you for participating in the discussion.

    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,

    Your message is awaiting moderation. Thank you for participating in the discussion.

    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

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

BT