Module Restful.Json

module Json: sig .. end

Functions for generating Json data.


type json = 
| String of string
| Num of int
| Float of float
| Bool of bool
| Null
| Array of json list
| Object of (string * json) list

The type of json data.

val string : string -> json

(string s) is (String s).

val num : int -> json

(num n) is (Num n).

val float : float -> json

(float f) is (Float f).

val bool : bool -> json

(bool b) is (Bool b).

val null : 'a -> json

(null x) is Null.

val array : ('a -> json) -> 'a list -> json

(array f xs) is (Array (map f xs)).

val obj : ('a -> json) -> (string * 'a) list -> json

(obj f alist) is (Object (map (fun (s,x) -> s, f x) alist)).

val of_option : ('a -> json) -> 'a option -> json

(of_option f (Some x)) is (f x) and (of_option f None) is Null.

val to_string : ?minify:bool -> json -> string

(to_string ?minify json): convert a json data structure to a string in Json representation.

val callback : ?minify:bool -> string -> json -> string

(callback ?minify cb json): convert a json data structure to a string in "Json callback" representation. You should use Restful.Json.content_type as your content-type.

val valid_id : string -> bool

See Restful.Valid.javascript_identifier.

val content_type : string

The correct content-type for Json data.

val json_of_jsonm : ([< `A of 'a list
| `Bool of bool
| `Float of float
| `Null
| `O of (string * 'a) list
| `String of string ]
as 'a) ->
json

json_of_jsonm is effectively of type Jsonm.json -> json i.e. it converts Bünzli's Jsonm representation, which is also the representation of Ezjsonm, to ours.