package ezjsonm
Install
dune-project
Dependency
Authors
Maintainers
Sources
sha256=527dbd3f930570ced1052f20b8844fe92a87adca7ec870fe9353695902f3d2b5
md5=e8f207c6cd2226b2c4784b1e56556797
doc/ezjsonm/Ezjsonm/index.html
Module Ezjsonm
An easy interface on top of the Jsonm library.
This version provides more convenient (but far less flexible) input and output functions that go to and from string values. This avoids the need to write signal code, which is useful for quick scripts that manipulate JSON.
More advanced users should go straight to the Jsonm library and use it directly, rather than be saddled with the Ezjsonm interface below.
Basic types
type value = [ | `Null| `Bool of bool| `Float of float| `String of string| `A of value list| `O of (string * value) list
]JSON fragments.
wrap v wraps the value v into a JSON array. To use when it is not possible to statically know that v is a value JSON value.
unwrap t is the reverse of wrap. It expects t to be a singleton JSON object and it return the unique element.
Reading JSON documents and values
val from_channel : in_channel -> [> t ]Read a JSON document from an input channel.
val from_string : string -> [> t ]Read a JSON document from a string.
val value_from_channel : in_channel -> valueRead a JSON value from an input channel.
val value_from_string : string -> valueRead a JSON value from a string.
Writing JSON documents and values
val to_channel : ?minify:bool -> out_channel -> t -> unitWrite a JSON document to an output channel.
val to_string : ?minify:bool -> t -> stringWrite a JSON document to a string. This goes via an intermediate buffer and so may be slow on large documents.
val value_to_channel : ?minify:bool -> out_channel -> value -> unitWrite a JSON value to an output channel.
val value_to_string : ?minify:bool -> value -> stringWrite a JSON value to a string. This goes via an intermediate buffer and so may be slow on large documents.
Low-level function to write directly to a Jsonm destination.
Constructors
val unit : unit -> valueSame as `Null.
val bool : bool -> valueSame as `Bool b.
val string : string -> valueSame as `String s.
val strings : string list -> [> t ]Same as `A [`String s1; ..; `String sn].
val int : int -> valueSame as `Float (float_of_int i).
val int32 : int32 -> valueSame as `Float (Int32.to_float i)
val int64 : int64 -> valueSame as `Float (Int64.to_float i)
val float : float -> valueSome as `Float f.
Build a triple.
Accessors
exception Parse_error of value * stringAll 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 : value -> unitCheck that the JSON document is `Null.
val get_bool : value -> boolExtract b from `Bool b.
val get_string : value -> stringExtract s from `String s.
val get_strings : value -> string listExtract s1;..;sn from `A [`String s1; ...; `String sn].
val get_int : value -> intExtract an integer.
val get_int32 : value -> int32Extract a 32-bits integer.
val get_int64 : value -> int64Extract a 64-bits integer.
val get_float : value -> floatExtract a float.
Extract the triple.
High-level functions
val mem : value -> string list -> boolIs the given path valid if the provided JSON document.
Find the sub-document adressed by the given path. Raise Not_found if the path is invalid.
Update the sub-document addressed by the given path. If the provided value is None, then removes the sub-document.
Apply a given function to a subdocument.
val encode_string : string -> valueConvert a (possibly non-valid UTF8) string to a JSON object.
val decode_string : value -> string optionConvert a JSON object to a (possibly non-valid UTF8) string. Return None if the JSON object is not a valid string.
val decode_string_exn : value -> stringConvert a JSON object to a (possibly non-valid UTF8) string.
val to_sexp : value -> Sexplib.Type.tConvert a JSON fragment to an S-expression.
val sexp_of_value : value -> Sexplib.Type.tAn alias of to_sexp
val sexp_of_t : t -> Sexplib.Type.tConvert a JSON object to an S-expression
val of_sexp : Sexplib.Type.t -> valueConvert an S-expression to a JSON fragment
val value_of_sexp : Sexplib.Type.t -> valueAN alias of of_sexp
val t_of_sexp : Sexplib.Type.t -> tConvert an S-expression to a JSON object