Module Kojson_pattern.K

module K: sig .. end
Patterns for Matching JSON Trees.


Primitive Patterns


val literal : Kojson.json -> Kojson.jin -> unit
literal v matches only the value v.
val convert : string -> (Kojson.json -> 'a) -> Kojson.jin -> 'a
convert type_name f performs the conversion f, intercepting Failure and re-raises them as a conversion error informing that a value of type_name was expected.
val any : Kojson.jin -> Kojson.json
json matches any value and returns it.
val null : Kojson.jin -> unit
null matches `Null.
val bool : Kojson.jin -> bool
bool matches a value of the form `Bool b and returns b.
val int : Kojson.jin -> int
int matches a value of the form `Int i and returns i.
val float : Kojson.jin -> float
float matches a value of the form `Float x and returns x.
val string : Kojson.jin -> string
string matches a value of the form `String s and returns s.
val string_enum : (string * 'a) list -> Kojson.jin -> 'a
string_enum lxs matches any of the keys of the association list lxs and returns the corresponding value.

Pattern Combinators


val list : (Kojson.jin -> 'a) -> Kojson.jin -> 'a list
list f matches `List vs if f matches v for each v in vs, and returns the list of values f v.
val array : (Kojson.jin -> 'a) -> Kojson.jin -> 'a array
array f matches the same inputs as list f, but returns an array instead of a list.
val assoc : (Kojson.jain -> 'a) -> Kojson.jin -> 'a
assoc f matches `Assoc vs if f matches vs and passes though the computed value f vs. The pattern f can be constructed using the Kojson_pattern.Ka module.
val assoc_or_null : (Kojson.jain -> 'a) -> Kojson.jin -> 'a
assoc_or_null f matches the same inputs as assoc f, in addition to `Null and `List [] given that f matches the empty association.
val first : (Kojson.jin -> 'a) list -> Kojson.jin -> 'a
first [f₁; …; fₙ] matches a value which is matched by either of the fᵢ patters, and returns the result of the first match.