package b0

  1. Overview
  2. Docs

JSON value generation.

Generation

type t

The type for generated JSON values.

val null : t

null is the generated JSON null value.

val bool : bool -> t

bool b is b as a generated JSON boolean value.

val int : int -> t

int i is i as a generated JSON number.

val float : float -> t

float f is f as a generated JSON number.

val string : string -> t

str s is s as a generated JSON string value.

type arr

The type for generated JSON arrays.

val arr : arr

arr is an empty array.

val arr_end : arr -> t

arr_end els is arr a a generated JSON value.

val el : t -> arr -> arr

el e arr is array arr wit e added at the end.

val el_if : bool -> (unit -> t) -> arr -> arr

el cond v arr is el (v ()) arr if cond is true and arr otherwise.

type obj

The type for generated JSON objects.

val obj : obj

obj is an empty object.

val obj_end : obj -> t

obj_end o is o as a generated JSON value.

val mem : string -> t -> obj -> obj

mem name v o is o with member name bound to value v added.

val mem_if : bool -> string -> (unit -> t) -> obj -> obj

mem_if cond name v o is mem name (v ()) o if cond is true and o otherwise.

Derived generators

val json : Json.t -> t

of_json v is the JSON value v as a generated value.

val path : B0_std.Fpath.t -> t

path p is p as a generated JSON string value.

val cmd : B0_std.Cmd.t -> t

cmd c is c as a generated JSON string array value.

val list : ('a -> t) -> 'a list -> t

list el l is l as a generated JSON array whose elements are generated using el.

val strf : ('a, Format.formatter, unit, t) format4 -> 'a

strf fmt ... is a JSON string generated value formatted according to fmt.

Output

val buffer_add : Buffer.t -> t -> unit

buffer_add b g adds the generated JSON value g to b.

val to_string : t -> string

to_string g is the generated JSON value g as a string.

OCaml

Innovation. Community. Security.