Module Key_value.Jsonm_object

type t = [
  1. | `Null
  2. | `Bool of bool
  3. | `Float of float
  4. | `String of string
  5. | `A of t list
  6. | `O of (string * t) list
]
include VALIDABLE with type t := t

Types

Visitors

A visitor is quite simple and can be summarised as follows:

let as_xxxx valid invalid observed_value =
  if is_xxx observed_value
  then valid (extract_xxx observed_value)
  else invalid ()
;;
val as_object : (t, (string * t) list, 'a) visitor

Visitor for Objects. For example, in Ezjsonm (which is a simpler wrapper for the Jsonm library), The AST is described in this way:

type value =
  [ `Null
  | `Bool of bool
  | `Float of float
  | `String of string
  | `A of value list
  | `O of (string * value) list
  ]

Implementing as_object would be like writing this:

let as_object valid invalid = function
  | `O kv -> valid kv
  | _ -> invalid ()
;;
val as_list : (t, t list, 'a) visitor

Visitor for List.

val as_atom : (t, string, 'a) visitor

Visitor for Atoms.

val as_string : (t, string, 'a) visitor

Visitor for String.

val as_boolean : (t, bool, 'a) visitor

Visitor for Boolean.

val as_integer : (t, int, 'a) visitor

Visitor for Integer.

val as_float : (t, float, 'a) visitor

Visitor for Float.

val as_null : (t, unit, 'a) visitor

Visitor for Null.