json-pointer - RFC 6901 JSON Pointer for OCaml#
A complete RFC 6901 JSON Pointer implementation for OCaml, providing parsing, serialization, evaluation, and mutation operations compatible with jsont codecs.
Key Features#
- Full RFC 6901 compliance with proper escape sequence handling
- Type-safe phantom types distinguish navigation vs append pointers
- Mutation operations for RFC 6902 JSON Patch support
- JMAP extended pointers (RFC 8620) with wildcard support
Usage#
(* Parse and evaluate a JSON Pointer *)
let json = Jsont_bytesrw.decode_string Jsont.json
{|{"foo": ["bar", "baz"], "a/b": 1}|} |> Result.get_ok
let value = Json_pointer.(get (of_string_nav "/foo/0") json)
(* value = Jsont.String ("bar", _) *)
(* Escape sequences: ~1 for /, ~0 for ~ *)
let value = Json_pointer.(get (of_string_nav "/a~1b") json)
(* value = Jsont.Number ("1", _) *)
Mutations for JSON Patch operations:
(* Add a new element to an array *)
let json' = Json_pointer.(add (of_string "/foo/-") json
~value:(Jsont.Json.string "qux"))
(* Remove an element *)
let json' = Json_pointer.(remove (of_string_nav "/foo/0") json)
Installation#
opam install json-pointer
Documentation#
API documentation is available via:
opam install json-pointer
odig doc json-pointer
License#
ISC