dojox/json/query (version 1.10)

Summary

Performs a JSONQuery on the provided object and returns the results. If no object is provided (just a query), it returns a "compiled" function that evaluates objects according to the provided query.

JSONQuery provides a comprehensive set of data querying tools including filtering, recursive search, sorting, mapping, range selection, and powerful expressions with wildcard string comparisons and various operators. JSONQuery generally supersets JSONPath and provides syntax that matches and behaves like JavaScript where possible.

JSONQuery evaluations begin with the provided object, which can referenced with $. From the starting object, various operators can be successively applied, each operating on the result of the last operation.

Supported Operators

dojox.json.query(queryString,object)

and

dojox.json.query(queryString)(object)

always return identical results. The first one immediately evaluates, the second one returns a

function that then evaluates the object.

Usage

query(query,obj);
Parameter Type Description
query String

Query string

obj Object
Optional

Target of the JSONQuery

See the dojox/json/query reference documentation for more information.

Examples

Example 1

dojox.json.query("foo",{foo:"bar"})

This will return "bar".

Example 2

evaluator = dojox.json.query("?foo='bar'&rating>3");

This creates a function that finds all the objects in an array with a property

foo that is equals to "bar" and with a rating property with a value greater than 3.

evaluator([{foo:"bar",rating:4},{foo:"baz",rating:2}])

This returns:

{foo:"bar",rating:4}

Example 3

evaluator = dojox.json.query("$[?price<15.00][\rating][0:10]");

This finds objects in array with a price less than 15.00 and sorts then

by rating, highest rated first, and returns the first ten items in from this filtered and sorted list.

Method Summary

Methods

Error in the documentation? Can’t find what you are looking for? Let us know!