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
$The root: the whole document..storeThe child namedstore..bicycleThen its childbicycle..colorThencolor→"red".
Result
"red"
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']
['store']The bracket form of.store. Quotes may be single or double.['bicycle']Same idea, one level down.['color']Same result as the dotted version.
Result
"red"
Good to know
- A query in JSONPath always begins with
$— that's also how the playground auto-detects it.