Something went wrong. Try again.
RFC6901 JSON Pointer implementation in OCaml using jsont
Something went wrong. Try again.
5 files
README.md
1-pointers #
A JSON Pointer is a sequence of string tokens. Its string form is empty for the
document root; otherwise, every token has a leading /. Within a token, ~
is written as ~0 and / as ~1.
The first example parses a pointer and builds the same value from unescaped tokens:
let parsed = Json_pointer.of_string "/users/0/display~1name"
let built =
Json_pointer.(root / "users" / "0" / "display/name")
let same = Json_pointer.equal parsed built
The library keeps tokens as strings. It does not guess whether "0" will be
an object member or an array index; evaluation settles that from the JSON value
later. Building with Json_pointer.of_tokens or the / operator also means
callers never have to escape tokens themselves.
Run the complete example:
$ cd example/1-pointers
$ opam install --deps-only --yes .
$ dune exec --root . ./pointers.exe
parsed: /users/0/display~1name
tokens: ["users"; "0"; "display/name"]
built: /users/0/display~1name
same pointer: true
escaped tokens: /a~1b/m~0n
invalid input: Invalid JSON Pointer: must be empty or start with '/': users/0
Json_pointer.of_string raises Jsont.Error for malformed input.
Json_pointer.of_string_result, used by the last line of the example, is more
convenient at untrusted-input boundaries.
Next steps #
2-evaluationapplies these tokens to a JSON value.3-uri-fragmentsshows the second RFC 6901 representation.
Folders and files #
pointers.mlis the complete program.dunedescribes its executable.dune-projectand1-pointers.opammake this a standalone project.