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
  1. /9 There is no element at index 9 — book has only 0 and 1 — so the whole pointer fails.

Result (it fails on purpose)

query error: no value at pointer '/store/book/9/title'

Try it in the playground

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/book
  1. store A 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 '/'

Try it in the playground

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.