Module Json_type.Build

module Build: sig .. end
This submodule provides some simple functions for building JSON data from other OCaml types.

Use open Json_type.Build when you want to convert JSON data into another OCaml type.


val null : Json_type.t
The Null value
val bool : bool -> Json_type.t
builds a JSON Bool
val int : int -> Json_type.t
builds a JSON Int
val float : float -> Json_type.t
builds a JSON Float
val string : string -> Json_type.t
builds a JSON String
val objekt : (string * Json_type.t) list -> Json_type.t
builds a JSON Object.

See Json_type.Browse.objekt for an explanation about the unusual spelling.

val array : Json_type.t list -> Json_type.t
builds a JSON Array.
val list : ('a -> Json_type.t) -> 'a list -> Json_type.t
list f l maps OCaml list l to a JSON list using function f to convert the elements into JSON values.

For example, list int [1; 2; 3] is a shortcut for Array [ Int 1; Int 2; Int 3 ].

val option : Json_type.t option -> Json_type.t
option x returns Null is x is None, or y if x is Some y.
val optional : ('a -> Json_type.t) -> 'a option -> Json_type.t
optional f x returns Null if x is None, or f x otherwise.

For example, list (optional int) [Some 1; Some 2; None] returns Array [ Int 1; Int 2; Null ].