EzjsonmAn 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.
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.
val from_channel : Stdlib.in_channel -> [> t ]Reading JSON documents and values
Read a JSON document from an input channel.
val from_string : string -> [> t ]Read a JSON document from a string.
val value_from_channel : Stdlib.in_channel -> valueRead a JSON value from an input channel.
val value_from_string : string -> valueRead a JSON value from a string.
val value_from_src : Jsonm.src -> valueLow-level function to read directly from a Jsonm source.
Error locations in a source document follow the Jsonm representation of pairs of pairs ((start_line, start_col), (end_line, end_col)) with 0-indexed lines and 1-indexed columns.
type read_value_error = [ | `Error of error_location * Jsonm.error |
| `Unexpected of [ `Lexeme of error_location * Jsonm.lexeme * string | `End_of_input ] |
]val read_error_description : [< read_error ] -> stringA human-readable description of an error -- without using the error location.
val read_error_location : [< read_error ] -> error_location optionIf the error is attached to a specific location in the buffer, return this location.
val from_channel_result : Stdlib.in_channel -> ([> t ], [> read_error ]) Stdlib.resultSee from_channel.
val from_string_result : string -> ([> t ], [> read_error ]) Stdlib.resultSee from_string.
val value_from_channel_result : Stdlib.in_channel -> (value, [> read_value_error ]) Stdlib.resultSee value_from_channel.
val value_from_string_result : string -> (value, [> read_value_error ]) Stdlib.resultSee value_from_string.
val value_from_src_result : Jsonm.src -> (value, [> read_value_error ]) Stdlib.resultSee value_from_src.
val to_channel : ?minify:bool -> Stdlib.out_channel -> t -> unitWrite a JSON document to an output channel.
val to_buffer : ?minify:bool -> Stdlib.Buffer.t -> t -> unitWrite a JSON document to a buffer.
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 -> Stdlib.out_channel -> value -> unitWrite a JSON value to an output channel.
val value_to_buffer : ?minify:bool -> Stdlib.Buffer.t -> value -> unitWrite a JSON value to a buffer.
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.
val value_to_dst : ?minify:bool -> Jsonm.dst -> value -> unitLow-level function to write directly to a Jsonm destination.
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.
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.
val mem : value -> string list -> boolmem v path is true if the given path is valid for the JSON document v.
Find the sub-document addressed by the given path. Raise Not_found if the path is invalid.
Find the sub-document addressed by the given path. Returns None 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 -> Sexplib0.Sexp.tConvert a JSON fragment to an S-expression.
val sexp_of_value : value -> Sexplib0.Sexp.tAn alias of to_sexp
val sexp_of_t : t -> Sexplib0.Sexp.tConvert a JSON object to an S-expression
val of_sexp : Sexplib0.Sexp.t -> valueConvert an S-expression to a JSON fragment
val value_of_sexp : Sexplib0.Sexp.t -> valueAN alias of of_sexp
val t_of_sexp : Sexplib0.Sexp.t -> tConvert an S-expression to a JSON object
val parse_error : value -> ('a, unit, string, 'b) Stdlib.format4 -> 'aRaise Parse_error