Take the 2-minute tour ×

When searching for items in complex JSON arrays and hashes, like:

    { "id": 1, "name": "One", "objects": [
        { "id": 1, "name": "Response 1", "objects": [
            // etc.

Is there some kind of query language I can used to find an item in [0].objects where id = 3?

share|improve this question
not unless you make one. Leave the querying to the server, and use REST to get only the data you need. –  zzzzBov Dec 12 '11 at 21:52
+1 good idea. Gonna write this tomorrow… –  user142019 Dec 12 '11 at 21:53
Not XPath, but I've found JLinq pretty good (which makes code to read like in(...).where(...).select(...)): hugoware.net/Projects/jLinq. –  pimvdb Dec 12 '11 at 22:00
This is frustrating because there's lots of libraries out there, but nothing approaching a commonly accepted standard. We have a library used by 3rd parties so we need to provide a query language that is widely known and used. –  David Thielen Jun 12 '12 at 18:06
Some other options are suggested here: stackoverflow.com/questions/777455/… –  Simon Jun 14 '13 at 3:09
show 1 more comment

10 Answers

up vote 32 down vote accepted

Yup, it's called JSONPath:

It's also integrated into DOJO.

share|improve this answer
Also used by Kynetx docs.kynetx.com/docs/KRL_and_JSONPath –  Eric Bloch Dec 13 '11 at 0:27
Brian's answer suggests that the jsonQuery module should be used instead of the jsonPath module in dojo. –  missingno Dec 15 '11 at 16:51
How solid is this? And I can't find a Java or C# version which is a deal killer for us. –  David Thielen Jun 12 '12 at 18:08
The site linked here provides for Javascript and PHP. If you need a Java implementation, there’s one here: code.google.com/p/json-path –  Paramaeleon Nov 16 '12 at 7:20
I should mention that JSONPath is not based on the XPath formal semantic. JSONiq might be a better option. –  wcandillon Jun 8 '13 at 10:45
show 1 more comment

I think JSONQuery replaced JSONPath in dojo.

From Dojo documentation:

JSONQuery is an extended version of JSONPath with additional features for security, ease of use, and 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.

JSONselect has another point of view on the question (CSS selector-like, rather than XPath) and has a JavaScript implementation.

share|improve this answer
The github JSONQuery link seems to be dead. JSONSelect also has a JavaScript version now. –  Henrik Dec 20 '12 at 15:06
add comment

Try to using JSPath

JSPath is a domain-specific language (DSL) that enables you to navigate and find data within your JSON documents. Using JSPath, you can select items of JSON in order to retrieve the data they contain.

JSPath for JSON like an XPath for XML.

It is heavily optimized both for Node.js and modern browsers.

share|improve this answer
add comment

Three other alternatives I am aware of are

  1. JSONiq specification, which specifies two subtypes of languages: one that hides XML details and provides JS-like syntax, and one that enriches XQuery syntax with JSON constructors and such. Zorba implements JSONiq.
  2. Corona, which builds on top of MarkLogic provides a REST interface for storing, managing, and searching XML, JSON, Text and Binary content.
  3. MarkLogic 6 and later provide a similar REST interface as Corona out of the box.


share|improve this answer
There is now a JSONiq implementation: Zorba 2.6 officially supports it. –  xqib-team Aug 29 '12 at 9:40
add comment

XQuery can be used to query JSON, provided that the processor offers JSON support. This is a straightforward example how BaseX can be used to find objects with "id" = 1:

        { "id": 1, "name": "Response 1", "objects": [ "etc." ] }
]')//value[.//id = 1]
share|improve this answer
add comment

To summarise some of the current options for traversing/filtering JSON data, and provide some syntax examples...

  • JSPath
    .automobiles{.maker === "Honda" && .year > 2009}.model

  • json:select() (inspired more by CSS selectors)
    .automobiles .maker:val("Honda") .model

  • JSONPath (inspired more by XPath)

I think JSPath looks the nicest, so I'm going to try and integrate it with my AngularJS + CakePHP app.

(I originally posted this answer in another thread but thought it would be useful here, also.)

share|improve this answer
add comment

ObjectPath is a query language similar to XPath or JSONPath, but much more powerful thanks to embedded arithmetic calculations, comparison mechanisms and built-in functions. See the syntax:

Find in the shop all shoes of red color and price less than 50

$..shoes.*[color is "red" and price < 50]

share|improve this answer
add comment

Json Pointer seem's to be getting growing support too.

share|improve this answer
add comment

Jsel is awesome and is based on a real XPath engine. It allows you to create XPath expressions to find any type of JavaScript data, not just objects (strings too).

You can create custom schemas and mappings to give you complete control over how your data is walkable by the XPath engine. A schema is a way of defining how elements, children, attributes, and node values are defined in your data. Then you can create your own expressions to suit.

Given you had a variable called data which contained the JSON from the question, you could use jsel to write:


This will return any node with an id attribute of 3. An attribute is any primitive (string, number, date, regex) value within an object.

share|improve this answer
add comment

@Naftule - with "defiant.js", it is possible to query a JSON structure with XPath expressions. Check out this evaluator to get an idea of how it works:


Unlike JSONPath, "defiant.js" delivers the full-scale support of the query syntax - of XPath on JSON structures.

The source code of defiant.js can be found here:

share|improve this answer
add comment

Your Answer


