JSONSelect

json:select()
CSS-like selectors for JSON.
`".author .drinkPref :first-child"`

    {
      "author": {
        "name": {
          "first": "Lloyd",
          "last": "Hilaiel"
        },
        "drinkPref": [
          "whiskey",
          "beer",
          "wine"
        ],
      },
      "thing": "JSONSelect site",
      "license": "(cc) BY-SA"
    }

JSONSelect is an experimental selector language for JSON.

It makes it easy to access data in complex JSON documents.

It feels like CSS.

Why not give it a try?

Current Selector (click to edit):

    {
        "name": {
            "first": "Lloyd",
            "last": "Hilaiel"
        },
        "favoriteColor": "yellow",
        "languagesSpoken": [
            {
                "lang": "Bulgarian",
                "level": "advanced"
            },
            {
                "lang": "English",
                "level": "native",
                "preferred": true
            },
            {
                "lang": "Spanish",
                "level": "beginner"
            }
        ],
        "seatingPreference": [
            "window",
            "aisle"
        ],
        "drinkPreference": [
            "whiskey",
            "beer",
            "wine"
        ],
        "weight": 172
    }

Choose A Selector...
.languagesSpoken .lang
.drinkPreference :first-child
.seatingPreference :nth-child(1)
."weight"
.lang
.favoriteColor
string.favoriteColor
string:last-child
string:nth-child(-n+2)
string:nth-child(odd)
string:nth-last-child(1)
:root
number
:has(:root > .preferred)
.preferred ~ .lang
:has(.lang:val("Spanish")) > .level
.lang:val("Bulgarian") ~ .level
.weight:expr(x<180) ~ .name .first

JSONSelect is dedicated to sad code everywhere that looks like this:

    if (foo && foo.bar && foo.bar.baz && foo.bar.baz.length > 2)
        return foo.bar.baz[2];
    return undefined;

Lloyd Hilaiel started it, and is surrounded by many awesome contributors.

Dave Herman provided the name, and lots of encouragement.

Mike Hanson gave deep feedback and ideas.

John Resig unwittingly contributed his design thoughts.

The jsonselect.org site design was inspired by Stephen Wildish.

JSON and CSS3 Selectors are the prerequisites to JSONSelect's existence, so thanks to you guys too.

Loading documentation...

Several different implementations of JSONSelect are available:

JavaScript: Get it documented, or minified (2.9k minified and gzipped). The code is on github.

node.js: `npm install JSONSelect`

ruby: A gem by Simon Menke: https://github.com/fd/json_select

Something missing from this list? Please, tell me about it.