JSONPath · lesson 1 of 13 · Basics

Root & child segments

Every JSONPath starts at the root $. Add child segments with dots (.name) or brackets (['name']) — brackets also cope with keys that contain spaces or symbols.

Examples

Example 1Dot notation

Document

{
  "store": {
    "book": [
      { "title": "Sayings of the Century", "author": "Nigel Rees",
        "category": "reference", "price": 8.95 },
      { "title": "Sword of Honour", "author": "Evelyn Waugh",
        "category": "fiction", "price": 12.99 },
      { "title": "Moby Dick", "author": "Herman Melville",
        "category": "fiction", "price": 8.99, "isbn": "0-553-21311-3" },
      { "title": "The Lord of the Rings", "author": "J. R. R. Tolkien",
        "category": "fiction", "price": 22.99, "isbn": "0-395-19395-8" }
    ],
    "bicycle": { "color": "red", "price": 19.95 }
  }
}

Query

$.store.bicycle.color
  1. $ The root: the whole document.
  2. .store The child named store.
  3. .bicycle Then its child bicycle.
  4. .color Then color → "red".

Result

"red"

Try it in the playground

Example 2Bracket notation — the same path

Document

{
  "store": {
    "book": [
      { "title": "Sayings of the Century", "author": "Nigel Rees",
        "category": "reference", "price": 8.95 },
      { "title": "Sword of Honour", "author": "Evelyn Waugh",
        "category": "fiction", "price": 12.99 },
      { "title": "Moby Dick", "author": "Herman Melville",
        "category": "fiction", "price": 8.99, "isbn": "0-553-21311-3" },
      { "title": "The Lord of the Rings", "author": "J. R. R. Tolkien",
        "category": "fiction", "price": 22.99, "isbn": "0-395-19395-8" }
    ],
    "bicycle": { "color": "red", "price": 19.95 }
  }
}

Query

$['store']['bicycle']['color']
  1. ['store'] The bracket form of .store. Quotes may be single or double.
  2. ['bicycle'] Same idea, one level down.
  3. ['color'] Same result as the dotted version.

Result

"red"

Try it in the playground

Good to know

  • A query in JSONPath always begins with $ — that's also how the playground auto-detects it.

About jsonquery

Query, format and learn JSON with jq, JSONPath, JMESPath and JSON Pointer. It is the engine of the desktop app, run in your browser.

Engine
The desktop app’s, compiled to WebAssembly
Licence
MIT (the engine and the app)
Source
GitHub
Contact
The contact form (private)
Public issues
GitHub
Legal
Privacy policy

Known limitations: a file over 10 MB opens read-only and one over 512 MB does not open here; the desktop app has no such limit.