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~1Stands for a literal/, so this pointer names the keya/b.
Result
1
Example 2A key that contains a tilde
Document
{
"a/b": 1,
"m~n": 8,
"c%d": 2,
"": 0
}Query
/m~0n~0Stands for a literal~, so this pointer names the keym~n.
Result
8
Good to know
- Nothing else needs escaping: spaces,
%, quotes and so on are written as they are —/c%dnames the keyc%d. ~01means a tilde followed by1, not a slash —~1is decoded first, so the order of the two characters matters.