JSON Pointer · lesson 3 of 6 · Special characters

Escaping / and ~

A key may contain / or ~, but both have a meaning inside a pointer, so they are written ~1 (for /) and ~0 (for ~).

Examples

Example 1A key that contains a slash

Document

{
  "a/b": 1,
  "m~n": 8,
  "c%d": 2,
  "": 0
}

Query

/a~1b
  1. ~1 Stands for a literal /, so this pointer names the key a/b.

Result

1

Try it in the playground

Example 2A key that contains a tilde

Document

{
  "a/b": 1,
  "m~n": 8,
  "c%d": 2,
  "": 0
}

Query

/m~0n
  1. ~0 Stands for a literal ~, so this pointer names the key m~n.

Result

8

Try it in the playground

Good to know

  • Nothing else needs escaping: spaces, %, quotes and so on are written as they are — /c%d names the key c%d.
  • ~01 means a tilde followed by 1, not a slash — ~1 is decoded first, so the order of the two characters matters.

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.