JSON Pointer · lesson 4 of 6 · When it doesn't work
Missing values & bad pointers
A pointer names exactly one value. If nothing is there, that is an error here (JSONPath, by contrast, returns an empty list). A pointer that isn't well-formed is a syntax error.
Examples
Example 1Nothing at that location
Document
{
"store": {
"book": [
{ "title": "Moby Dick", "price": 8.99 },
{ "title": "Ulysses", "price": 12.5 }
],
"bicycle": { "color": "red" }
}
}Query
/store/book/9/title/9There is no element at index 9 —bookhas only 0 and 1 — so the whole pointer fails.
Result (it fails on purpose)
query error: no value at pointer '/store/book/9/title'
Example 2Not a pointer at all
Document
{
"store": {
"book": [
{ "title": "Moby Dick", "price": 8.99 },
{ "title": "Ulysses", "price": 12.5 }
],
"bicycle": { "color": "red" }
}
}Query
store/bookstoreA pointer must be empty or start with/; this one starts with a letter.
Result (it fails on purpose)
query syntax error: a JSON pointer must be empty (whole document) or start with '/'