RFC6901 JSON Pointer implementation in OCaml using jsont
README.md

2-evaluation #

The first example built pointers. This one applies them to a Jsont.json document.

Use Json_pointer.get when the location is required:

let grace =
  Json_pointer.get (Json_pointer.of_string "/users/1/name") document

It returns the JSON value or raises Jsont.Error with the failing location. For optional data, Json_pointer.find returns None instead. A third form, Json_pointer.get_result, keeps the detailed error in a result value.

Run the complete example:

$ cd example/2-evaluation
$ opam install --deps-only --yes .
$ dune exec --root . ./evaluation.exe
required value: "Grace"
/users/0/name -> "Ada"
/0 -> "zero is an object member"
/- -> "hyphen is too"
/users/9 -> not found

Notice that 0 selects an array element below /users, but selects the member named "0" at the document root. Likewise, - is an ordinary object member. It becomes special only as the final array token of an RFC 6902 add operation.

Next steps #

Folders and files #

Up to the tutorial index