Query Language for JSON?

A new data querying tool for has been added to Dojo 1.2. JSONQuery is a new module intended to succeed and improve upon the JSONPath module introduced in Dojo 1.1. JSONQuery provides a comprehensive set of data querying tools including filtering, recursive search, sorting, mapping, range selection, and flexible expressions with wildcard string comparisons and various operators. JSONQuery provides safe evaluation with language agnostic expressions that prevents arbitrary code execution. It also uses intuitive result-based evaluation that allows successive query operations. Furthermore, the new JSONQuery module provides significant performance improvements, with 20-100x faster execution with the common filter operation on large arrays than the JSONPath module. JSONQuery generally supersets the functionality of JSONPath and provides syntax that matches and behaves like JavaScript where the syntax intersects for maximum ease of use.

var results = jLinq.from(records.users) 
//you can join records 
.join(records.locations, "location", "locationId", "id") 
//write queries on the data 
.startsWith("firstname", "j") 
.or("k") //automatically remembers field and command names 
//even query joined items 
.equals("location.state", "TX") 
//and even do custom selections 
.select(function(rec) { 
return { 
: rec.firstname + " " + rec.lastname, 
: rec.location.city, 
: (rec.age + 10) 

data = {foo:"bar"};
results = dojox.json.query("$.foo",data);
results -> "bar"
data = {foo:"bar"};
results = dojox.json.query("$.foo",data);
results -> "bar"

Build smarter apps with Machine Learning, Bots, Cognitive Services - Start free.

Start Learning Now