JSON.Pointer
implements RFC 6901 JSON Pointer, addressing a value inside a
JSON document with a string such as /foo/0/bar.
array-index
(Fn [(Ref String a)] (Maybe Int))
(array-index s)
parses a reference token as an array index.
Returns Nothing unless the token is 0 or a positive integer without a
leading zero, per RFC 6901. The end-of-array token - is not an index and
also yields Nothing.
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; array tokens follow array-index.
(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, addressing the whole document. A
non-empty pointer must begin with / or Nothing is returned. Empty tokens
are preserved, so 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.