JSON.Pointer
implements RFC 6901 JSON Pointer, addressing a value inside a
JSON document with a string such as /foo/0/bar.
escape
(Fn [(Ref String a)] String)
(escape s)
encodes a single reference token, turning ~ into ~0 and /
into ~1 so it can be embedded in a pointer string.
get
(Fn [(Ref JSON a), (Ref String b)] (Maybe JSON))
(get doc pointer)
resolves an RFC 6901 JSON Pointer against doc, returning a copy
of the addressed value or Nothing.
The empty pointer addresses the whole document. Object keys match by string.
An array token must be 0 or a positive integer without a leading zero; the
- end-of-array token, out-of-range indices, indexing a non-container, and
invalid pointers all yield Nothing.
(JSON.Pointer.get &doc "/foo/0")
parse
(Fn [(Ref String a)] (Maybe (Array String)))
(parse p)
parses a pointer string into its decoded reference tokens.
The empty string yields an empty token array, which addresses the whole
document. A non-empty pointer must begin with /, otherwise Nothing is
returned. Empty tokens are preserved: a trailing / addresses the
empty-string key.
unescape
(Fn [(Ref String a)] String)
(unescape s)
decodes a single reference token, turning ~1 back into /
and ~0 back into ~ in a single left-to-right pass, per RFC 6901.