Library
Module
Module type
Parameter
Class
Class type
Ints, floats and strings literals are systematically preserved using `Intlit
, `Floatlit
and `Stringlit
. This module also supports the specific syntax for variants and tuples supported by Yojson.Safe
.
type t = [
| `Null
| `Bool of bool
| `Intlit of string
| `Floatlit of string
| `Stringlit of string
| `Assoc of (string * t) list
| `List of t list
| `Tuple of t list
| `Variant of string * t option
]
All possible cases defined in Yojson:
("abc", 123)
.<"Foo">
or <"Bar":123>
.val pp : Stdlib.Format.formatter -> t -> unit
Pretty printer, useful for debugging
val show : t -> string
Convert value to string, useful for debugging
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.
val to_string :
?buf:Stdlib.Buffer.t ->
?len:int ->
?suf:string ->
?std:bool ->
t ->
string
Write a compact JSON value to a string.
val to_channel :
?buf:Stdlib.Buffer.t ->
?len:int ->
?suf:string ->
?std:bool ->
Stdlib.out_channel ->
t ->
unit
Write a compact JSON value to a channel. Note: the out_channel
is not flushed by this function.
See to_string
for the role of the optional arguments.
val to_output :
?buf:Stdlib.Buffer.t ->
?len:int ->
?suf:string ->
?std:bool ->
< output : string -> int -> int -> int.. > ->
t ->
unit
Write a compact JSON value to an OO channel.
See to_string
for the role of the optional arguments.
val to_file : ?len:int -> ?std:bool -> ?suf:string -> string -> t -> unit
Write a compact JSON value to a file. See to_string
for the role of the optional arguments.
val to_buffer : ?suf:string -> ?std:bool -> Stdlib.Buffer.t -> t -> unit
Write a compact JSON value to an existing buffer. See to_string
for the role of the optional argument.
val seq_to_string :
?buf:Stdlib.Buffer.t ->
?len:int ->
?suf:string ->
?std:bool ->
t Stdlib.Seq.t ->
string
Write a sequence of suf
-suffixed compact one-line JSON values to a string.
val seq_to_channel :
?buf:Stdlib.Buffer.t ->
?len:int ->
?suf:string ->
?std:bool ->
Stdlib.out_channel ->
t Stdlib.Seq.t ->
unit
Write a sequence of suf
-suffixed compact one-line JSON values to a channel.
val seq_to_file :
?len:int ->
?suf:string ->
?std:bool ->
string ->
t Stdlib.Seq.t ->
unit
Write a sequence of suf
-suffixed compact one-line JSON values to a file.
val seq_to_buffer :
?suf:string ->
?std:bool ->
Stdlib.Buffer.t ->
t Stdlib.Seq.t ->
unit
Write a sequence of suf
-suffixed compact one-line JSON values to an existing buffer.
val write_t : Stdlib.Buffer.t -> t -> unit
Write the given JSON value to the given buffer. Provided as a writer function for atdgen.
Sort object fields (stable sort, comparing field names and treating them as byte sequences)
val pretty_print : ?std:bool -> Stdlib.Format.formatter -> t -> unit
Pretty-print into a Format.formatter
. See to_string
for the role of the optional std
argument.
val pretty_to_string : ?std:bool -> t -> string
Pretty-print into a string. See to_string
for the role of the optional std
argument.
val pretty_to_channel : ?std:bool -> Stdlib.out_channel -> t -> unit
Pretty-print to a channel. See to_string
for the role of the optional std
argument.
Combined parser and pretty-printer. See to_string
for the role of the optional std
argument.
Combined parser and printer. See to_string
for the role of the optional std
argument.
val from_string :
?buf:Stdlib.Buffer.t ->
?fname:string ->
?lnum:int ->
string ->
t
Read a JSON value from a string.
val from_channel :
?buf:Stdlib.Buffer.t ->
?fname:string ->
?lnum:int ->
Stdlib.in_channel ->
t
Read a JSON value from a channel. See from_string
for the meaning of the optional arguments.
val from_file :
?buf:Stdlib.Buffer.t ->
?fname:string ->
?lnum:int ->
string ->
t
Read a JSON value from a file. See from_string
for the meaning of the optional arguments.
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.
val seq_from_string :
?buf:Stdlib.Buffer.t ->
?fname:string ->
?lnum:int ->
string ->
t Stdlib.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.
val seq_from_channel :
?buf:Stdlib.Buffer.t ->
?fin:(unit -> unit) ->
?fname:string ->
?lnum:int ->
Stdlib.in_channel ->
t Stdlib.Seq.t
Input a sequence of JSON values from a channel. Whitespace between JSON values is fine but not required.
val seq_from_file :
?buf:Stdlib.Buffer.t ->
?fname:string ->
?lnum:int ->
string ->
t Stdlib.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.
val seq_from_lexbuf :
lexer_state ->
?fin:(unit -> unit) ->
Stdlib.Lexing.lexbuf ->
t Stdlib.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_line Stdlib.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.
val lineseq_from_file :
?buf:Stdlib.Buffer.t ->
?fname:string ->
?lnum:int ->
string ->
json_line Stdlib.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.
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.