package jsont
Module Jsont.Path
JSON paths.
Paths are used for keeping track of erroring contexts and for specifying query and update locations.
Indices
Paths
val root : troot is the root path.
val is_root : t -> boolis_root p is true iff p is the root path.
rev_indices p are the indices of p in reverse order, the last indexing operation appears first.
of_string s parses a path according to the path syntax.
Path syntax
Path provide a way for end users to address JSON and edit locations.
A path is a sequence of member and list indexing operations. Applying the path to a JSON value leads to either a JSON value, or nothing if one of the indices does not exist, or an error if ones tries to index a non-indexable value.
Here are a few examples of paths.
{
"ocaml": {
"libs": ["jsont", "brr", "cmdliner"]
}
}ocaml.libs # value of member "libs" of member "ocaml"
ocaml.libs.[0] # first element of member "libs" of member "ocaml"More formally a path is a . seperated list of indices. An index is written [i]. i can a zero-based list index. Or i can be an object member name n. If there is no ambiguity, the surrounding brackets can be dropped.
Notes.
- The syntax has no form of quoting at the moment this means key names can't contain,
[,], or start with a number. - It would be nice to be able to drop the dots in order to be compatible with JSONPath syntax.
- Reintroduce and implement negative indices (they are parsed).