Module Ezjsonm
type t = TODO: a
The type of JSON documents.
val from_string : string -> t
Read a JSON document from a string.
val to_channel : ?minify:bool -> Pervasives.out_channel -> t -> unit
Write a JSON document to an output channel.
val to_string : ?minify:bool -> t -> string
Write a JSON document to a string. This goes via an intermediate
buffer and so may be slow on large documents.
val unit : t
Same as
`Null
.
val bool : bool -> t
Same as
`Bool b
.
val string : string -> t
Same as
`String s
.
val strings : string list -> t
Same as
`A [`String s1; ..; `String sn]
.
val int : int -> t
Same as
`Float (int_of_string i)
.
val float : float -> t
Some as
`Float f
.
val list : 'a -> t -> 'a list -> t
Build a list of values.
val option : 'a -> t -> 'a option -> t
Either
`Null
or a JSON value.
val dict : (string * t) list -> t
Build a dictionnary.
val pair : 'a -> t -> 'b -> t -> ('a * 'b) -> t
Build a pair.
exception Parse_error of t * string
All the following accessor functions expect the provided JSON
document to be of a certain kind. In case this is not the case,
Parse_error
is raised.
val get_unit : t -> unit
Check that the JSON document is
`Null
.
val get_bool : t -> bool
Extract
b
from `Bool b
.
val get_string : t -> string
Extract
s
from `String s
.
val get_strings : t -> string list
Extract
s1;..;sn
from `A [`String s1; ...; `String sn]
.
val get_int : t -> int
Extract an integer.
val get_float : t -> float
Extract a float.
val get_list : t -> 'a -> t -> 'a list
Extract elements from a list document..
val get_option : t -> 'a -> t -> 'a option
Extract an optional document.
val get_dict : t -> (string * t) list
Extract the elements from a dictionnary document.
val get_pair : t -> 'a -> t -> 'b -> t -> ('a * 'b)
Extract the pairs.
val mem : t -> string list -> bool
Is the given path valid if the provided JSON document.
val find : t -> string list -> t
Find the sub-document adressed by the given path. Raise
Not_found
if the path is invalid.
val update : t -> string list -> t option -> t
Update the sub-document addressed by the given path. If the
provided value is
None
, then removes the sub-document.
val map : t -> t option -> t -> string list -> t
Apply a given function to a subdocument.