Module Kxclib.Json

type jv = [
  1. | `null
  2. | `bool of bool
  3. | `num of float
  4. | `str of string
  5. | `arr of jv list
  6. | `obj of (string * jv) list
]
type jv_field = string * jv
type jv_fields = jv_field list
type jv_kind = [
  1. | `null
  2. | `bool
  3. | `num
  4. | `str
  5. | `arr
  6. | `obj
]
val classify_jv : jv -> jv_kind
val string_of_jv_kind : jv_kind -> string
val normalize : jv -> jv
val normalize_fields : jv_fields -> jv_fields
val eqv : jv -> jv -> bool

whether two json value are equivalent, i.e. equal while ignoring ordering of object fields

val pp_unparse : ppf -> jv -> unit

pp_unparse ppf j output j as a JSON string. NB: this function does not check if j contains any `str s where s is an invalid UTF-8 string. it just assumes so.

val unparse : jv -> string

unparse j convert j to a JSON string using pp_unparse. see pp_unparse for caveats.

val pp_lit : ppf -> jv -> unit

pp_lit ppf j output j in a format that can be used as an OCaml literal.

val show : jv -> string

show j convert j to a string using pp_lit, which is a string that can be used as an OCaml literal.

type jvpath = [ `f of string | `i of int ] as 'path_component list

an empty path designate the root element

val pp_jvpath : ppf -> jvpath -> unit

print a human-friendly version of the jvpath. e.g.

  • pp_jvpath [] prints . (a single dot)
  • pp_jvpath [`f "foo"] prints .foo
  • pp_jvpath [`f "foo"; `f "bar"] prints .foo.bar
  • pp_jvpath [`f "foo"; `i 4] prints .foo[4]
  • pp_jvpath [`i 3] prints .[3]
  • pp_jvpath [`i 3; `i 4] prints .[3][4]
  • pp_jvpath [`i 3; `f "bar"] prints .[3].bar
  • pp_jvpath [`f "f!oo"] prints .["f!oo"]
val unparse_jvpath : jvpath -> string

unparse_jvpath path converts path to string in the same syntax as pp_jvpath

val parse_jvpath' : ?check_root:[ `check_root_prefix | `no_check ] -> string -> (jvpath, [ `pos of int | `premature_end of int ]) Stdlib.result

parse jvpath conforming the syntax of pp_jvpath

val parse_jvpath_opt : ?check_root:[ `check_root_prefix | `no_check ] -> string -> jvpath option
val parse_jvpath_exn : ?check_root:[ `check_root_prefix | `no_check ] -> string -> jvpath
type legacy = [
  1. | `arr of jv list
  2. | `obj of (string * jv) list
]
val of_legacy : legacy -> jv
val to_legacy : jv -> legacy option
type yojson = [ `Null | `Bool of bool | `Int of int | `Intlit of string | `Float of float | `String of string | `Assoc of (string * 't) list | `List of 't list | `Tuple of 't list | `Variant of string * 't option ] as 't

Yojson.Safe.t

val of_yojson : yojson -> jv
val to_yojson : jv -> yojson
type yojson' = [ `Null | `Bool of bool | `Int of int | `Float of float | `String of string | `Assoc of (string * 't) list | `List of 't list ] as 't

Yojson.Basic.t

val yojson_basic_of_safe : yojson -> yojson'
val yojson_safe_of_basic : yojson' -> yojson
type jsonm = jsonm_token seq
and jsonm_token = [
  1. | `Null
  2. | `Bool of bool
  3. | `String of string
  4. | `Float of float
  5. | `Name of string
  6. | `As
  7. | `Ae
  8. | `Os
  9. | `Oe
]
type 'loc jsonm' = ('loc * jsonm_token) seq
type 'loc jsonm_pe = [
  1. | `empty_document
  2. | `premature_end of 'loc
    (*

    with loc of the starting token of the inner-most structure (viz. array/object)

    *)
  3. | `expecting_value_at of 'loc
  4. | `unexpected_token_at of 'loc * jsonm_token
]
val of_jsonm' : 'loc jsonm' -> (jv * 'loc jsonm', 'loc jsonm_pe) Stdlib.result
val of_jsonm : jsonm -> (jv * jsonm) option
val to_jsonm : jv -> jsonm