JSON Pointer · lesson 5 of 6 · When it doesn't work

What pointers can't do

A pointer names one exact location. There is no negative index, no wildcard and no filter — for those, use JSONPath, jq or JMESPath.

Examples

Example 1No negative indexes

Document

{
  "store": {
    "book": [
      { "title": "Moby Dick", "price": 8.99 },
      { "title": "Ulysses", "price": 12.5 }
    ],
    "bicycle": { "color": "red" }
  }
}

Query

/store/book/-1
  1. -1 RFC 6901 has no negative indexes (jq has .[-1], JSONPath [-1]).

Result (it fails on purpose)

query error: no value at pointer '/store/book/-1'

Try it in the playground

Example 2No wildcards

Document

{
  "store": {
    "book": [
      { "title": "Moby Dick", "price": 8.99 },
      { "title": "Ulysses", "price": 12.5 }
    ],
    "bicycle": { "color": "red" }
  }
}

Query

/store/book/*/title
  1. * * is looked up as an ordinary key literally named *, which doesn't exist.

Result (it fails on purpose)

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

Try it in the playground

Good to know

  • A lone - (as in /store/book/-) means "the position after the last element" — meaningful when adding with JSON Patch, but never a readable value.
  • Want every title? JSONPath: $.store.book[*].title · jq: .store.book[].title · JMESPath: store.book[*].title.

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.