RFC6901 JSON Pointer implementation in OCaml using jsont
JavaScript 78.4%
OCaml 7.4%
HTML 6.0%
CSS 2.6%
Perl 2.4%
Raku 0.8%
Dune 0.1%
Other 2.3%
26 1 0

Clone this repository

https://tangled.org/anil.recoil.org/ocaml-json-pointer
git@git.recoil.org:anil.recoil.org/ocaml-json-pointer

For self-hosted knots, clone URLs may differ based on your setup.

README.md

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