Legend:
Library
Module
Module type
Parameter
Class
Class type
This module supports a specific syntax for variants and tuples in addition to the standard JSON nodes. Arbitrary integers are supported and represented as a decimal string using `Intlit when they cannot be represented using OCaml's int type (31 or 63 bits depending on the platform).
This module is recommended for intensive use or OCaml-friendly use of JSON.
equal a b is the monomorphic equality. Determines whether two JSON values are considered equal. In the case of JSON objects, the order of the keys does not matter, except for duplicate keys which will be considered equal as long as they are in the same input order.
Tuples are converted to JSON arrays, Variants are converted to JSON strings or arrays of a string (constructor) and a json value (argument). Long integers are converted to JSON strings.
val to_string :
?buf:Stdlib.Buffer.t ->?len:int ->?suf:string ->?std:bool ->t->
string
Write a compact JSON value to a string.
parameterbuf
allows to reuse an existing buffer created with Buffer.create. The buffer is cleared of all contents before starting and right before returning.
parameterlen
initial length of the output buffer.
parametersuf
appended to the output as a suffix, defaults to empty string.
parameterstd
use only standard JSON syntax, i.e. convert tuples and variants into standard JSON (if applicable), refuse to print NaN and infinities, require the root node to be either an object or an array. Default is false.
This alias is provided for backward compatibility. New code should refer to Yojson.lexer_state directly.
val init_lexer :
?buf:Stdlib.Buffer.t ->?fname:string ->?lnum:int ->unit ->lexer_state
This alias is provided for backward compatibility. New code should use Yojson.init_lexer directly.
val from_lexbuf : lexer_state->?stream:bool ->Stdlib.Lexing.lexbuf ->t
Read a JSON value from a lexbuf. A valid initial lexer_state can be created with init_lexer. See from_string for the meaning of the optional arguments and raised exceptions.
parameterstream
indicates whether more data may follow. The default value is false and indicates that only JSON whitespace can be found between the end of the JSON value and the end of the input.
val seq_from_string :
?buf:Stdlib.Buffer.t ->?fname:string ->?lnum:int ->string ->tStdlib.Seq.t
Input a sequence of JSON values from a string. Whitespace between JSON values is fine but not required. See from_string for the meaning of the optional arguments and raised exceptions.
val seq_from_channel :
?buf:Stdlib.Buffer.t ->?fin:(unit -> unit)->?fname:string ->?lnum:int ->Stdlib.in_channel ->tStdlib.Seq.t
Input a sequence of JSON values from a channel. Whitespace between JSON values is fine but not required.
parameterfin
finalization function executed once when the end of the sequence is reached either because there is no more input or because the input could not be parsed, raising an exception.
When the parsing and the finalizer both raised, Finally (exn, fin_exn) is raised, exn being the parsing exception and fin_exn the finalizer one.
See from_string for the meaning of the other optional arguments and other raised exceptions.
val seq_from_file :
?buf:Stdlib.Buffer.t ->?fname:string ->?lnum:int ->string ->tStdlib.Seq.t
Input a sequence of JSON values from a file. Whitespace between JSON values is fine but not required.
See from_string for the meaning of the optional arguments and raised exceptions.
val seq_from_lexbuf :
lexer_state->?fin:(unit -> unit)->Stdlib.Lexing.lexbuf ->tStdlib.Seq.t
Input a sequence of JSON values from a lexbuf. A valid initial lexer_state can be created with init_lexer. Whitespace between JSON values is fine but not required.
The type of values resulting from a parsing attempt of a JSON value.
val lineseq_from_channel :
?buf:Stdlib.Buffer.t ->?fin:(unit -> unit)->?fname:string ->?lnum:int ->Stdlib.in_channel ->json_lineStdlib.Seq.t
Input a sequence of JSON values, one per line, from a channel. Exceptions raised when reading malformed lines are caught and represented using `Exn.
See seq_from_channel for the meaning of the optional fin argument. See from_string for the meaning of the other optional arguments and raised exceptions.
val lineseq_from_file :
?buf:Stdlib.Buffer.t ->?fname:string ->?lnum:int ->string ->json_lineStdlib.Seq.t
Input a sequence of JSON values, one per line, from a file. Exceptions raised when reading malformed lines are caught and represented using `Exn.
See seq_from_channel for the meaning of the optional fin argument. See from_string for the meaning of the other optional arguments and raised exceptions.
val read_t : lexer_state->Stdlib.Lexing.lexbuf ->t
Read a JSON value from the given lexer_state and lexing buffer and return it. Provided as a reader function for atdgen.