Legend:
Library
Module
Module type
Parameter
Class
Class type
Library
Module
Module type
Parameter
Class
Class type
include module type of struct include Yojson.Safe end
val pp : Format.formatter -> {t}2 -> unit
Pretty printer, 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_basic : {t}2 -> Yojson.Basic.t
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.
Examples:
`Tuple [ `Int 1; `Float 2.3 ] -> `List [ `Int 1; `Float 2.3 ] `Variant ("A", None) -> `String "A" `Variant ("B", Some x) -> `List [ `String "B", x ] `Intlit "12345678901234567890" -> `String "12345678901234567890"
val to_string :
?buf:Buffer.t ->
?len:int ->
?suf:string ->
?std:bool ->
{t}2 ->
string
Write a compact JSON value to a string.
val to_channel :
?buf:Buffer.t ->
?len:int ->
?suf:string ->
?std:bool ->
out_channel ->
{t}2 ->
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 and raised exceptions.
val to_output :
?buf:Buffer.t ->
?len:int ->
?suf:string ->
?std:bool ->
< output : string -> int -> int -> int.. > ->
{t}2 ->
unit
Write a compact JSON value to an OO channel.
See to_string
for the role of the optional arguments and raised exceptions.
Write a compact JSON value to a file. See to_string
for the role of the optional arguments and raised exceptions.
val to_buffer : ?suf:string -> ?std:bool -> Buffer.t -> {t}2 -> unit
Write a compact JSON value to an existing buffer. See to_string
for the role of the optional argument and raised exceptions.
Write a sequence of suf
-suffixed compact one-line JSON values to a string.
val seq_to_channel :
?buf:Buffer.t ->
?len:int ->
?suf:string ->
?std:bool ->
out_channel ->
{t}2 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}2 Seq.t ->
unit
Write a sequence of suf
-suffixed compact one-line JSON values to a file.
Write a sequence of suf
-suffixed compact one-line JSON values to an existing buffer.
val write_t : Buffer.t -> {t}2 -> 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 -> Format.formatter -> {t}2 -> unit
Pretty-print into a Format.formatter
. See to_string
for the role of the optional std
argument.
Pretty-print into a string. See to_string
for the role of the optional std
argument. See pretty_print
for raised exceptions.
val pretty_to_channel : ?std:bool -> out_channel -> {t}2 -> unit
Pretty-print to a channel. See to_string
for the role of the optional std
argument. See pretty_print
for raised exceptions.
Combined parser and pretty-printer. See to_string
for the role of the optional std
argument and raised exceptions.
Combined parser and printer. See to_string
for the role of the optional std
argument and raised exceptions.
type lexer_state = {
buf : Buffer.t;
mutable lnum : int;
mutable bol : int;
mutable fname : string option;
}
This alias is provided for backward compatibility. New code should refer to Yojson.lexer_state
directly.
val init_lexer :
?buf: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 -> Lexing.lexbuf -> {t}2
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.
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:Buffer.t ->
?fin:(unit -> unit) ->
?fname:string ->
?lnum:int ->
in_channel ->
{t}2 Seq.t
Input a sequence of JSON values from a channel. Whitespace between JSON values is fine but not required.
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) ->
Lexing.lexbuf ->
{t}2 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:Buffer.t ->
?fin:(unit -> unit) ->
?fname:string ->
?lnum:int ->
in_channel ->
json_line 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.
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 -> Lexing.lexbuf -> {t}2
Read a JSON value from the given lexer_state and lexing buffer and return it. Provided as a reader function for atdgen.
module Util = Yojson.Safe.Util
This module provides combinators for extracting fields from JSON values.
include sig ... end
type t = Yojson.Safe.t
val from_channel :
?fname:string ->
?lnum:int ->
in_channel ->
(t, string) result