package equinoxe

  1. Overview
  2. Docs

The Json module provides helpers to manipulate JSON objects.

type t

Abstract type to represent JSON objects.

Creation

val create : ?kind:[ `Str of string | `Float of float | `Obj | `Arr ] -> unit -> t

create ~kind () generates a new t object. Default kind value is `Obj.

val error : string -> t

error msg produces a type t from an error message.

val of_string : string -> t

of_string str takes a string str representing a JSON and transform it into an t object you can manipulate with this module.

Getters

val geto : t -> string -> t

geto json field_name returns the t value associated to the field_name.

val geta : t -> int -> t

geta json nth. returns the t value associated to the nth element in the json.

val geto_from_a : t -> (string * string) -> t

getao json (k,v) returns the t value object associated with the first element in an array of object which contains the tuple (k,v).

val to_int_r : t -> (int, [ `Msg of string ]) result

to_int_r json transforms the json object into an int result with a printable error in case of failure.

val to_float_r : t -> (float, [ `Msg of string ]) result

to_float_r json transforms the json object into an float result with a printable error in case of failure.

val to_string_r : t -> (string, [ `Msg of string ]) result

to_string json transforms the json into a string result with a printable error in case of failure.

val to_unit_r : t -> (unit, [ `Msg of string ]) result

to_unit_r json returns a result with a unit value. It unwraps the errors and returns unit if there is no error.

val pp_r : t -> (unit, [ `Msg of string ]) result

pp_r json prints the json if it's a well format json and returns Ok (). Otherwise, it returns an error.

Setters

val addo : t -> (string * t) -> t

addo json (key,value) add a key-value to an object field.

val adda : t -> t -> t

adda json t value add a value to an array.

val export : t -> (string, [ `Msg of string ]) result

export json returns a string that represents the json.

module Infix : sig ... end

Infix operator for Json.t.

module Private : sig ... end

/!\ Private area should not be used while using the API!