RFC6901 JSON Pointer implementation in OCaml using jsont
1.7 kB · 40 lines
Markdown
at main

Tutorial #

These numbered examples form a step-by-step json-pointer tutorial. Each one is a complete Dune project with a small executable and a README that explains the new idea. Start with 1-pointers, or jump directly to the topic you need.

  • 1-pointers — parse pointers, inspect their tokens, and build them without manual escaping.
  • 2-evaluation — resolve required and optional values while letting the JSON value determine whether a token is a member or index.
  • 3-uri-fragments — convert pointers to and from their percent-encoded URI fragment representation.
  • 4-json-patch — apply the six RFC 6902 operations as pure transformations.
  • 5-jsont-codecs — extract and update typed values by composing pointers with Jsont codecs.
  • 6-jmap — evaluate RFC 8620 result-reference wildcards and decode their results.

Running an example #

Each directory has its own .opam file. Once json-pointer is available in your opam switch, run an example like this:

$ cd example/1-pointers
$ opam install --deps-only --yes .
$ dune exec --root . ./pointers.exe

When working from this source checkout before the package is released, install the checkout once with opam install . from the repository root, then use the same commands.

The examples use Jsont_bytesrw only to turn JSON text into Jsont.json values and back. All pointer behavior comes from json-pointer itself.

For a single-page reference with more detail, see the odoc tutorial.