Module Yojson

module Yojson: sig .. end
The Yojson library provides runtime functions for reading and writing JSON data from OCaml. It addresses a few shortcomings of its predecessor json-wheel and is about twice as fast (2.7x reading, 1.3x writing; results may vary). The design goals of Yojson are the following:
Author(s): Martin Jambon
See also JSON specification


Shared types and functions


val version : string
exception Json_error of string
val json_error : string -> 'a
type lexer_state = {
   buf : Bi_outbuf.t; (*
Buffer used to accumulate substrings
*)
   mutable lnum : int; (*
Current line number (counting from 1)
*)
   mutable bol : int; (*
Absolute position of the first character of the current line (counting from 0)
*)
   mutable fname : string option; (*
Name referencing the input file in error messages
*)
}
module Lexer_state: sig .. end
val init_lexer : ?buf:Bi_outbuf.t -> ?fname:string -> ?lnum:int -> unit -> lexer_state
Create a fresh lexer_state record.
val write_null : Bi_outbuf.t -> unit -> unit
val write_bool : Bi_outbuf.t -> bool -> unit
val write_int : Bi_outbuf.t -> int -> unit
val write_float : Bi_outbuf.t -> float -> unit
val write_std_float : Bi_outbuf.t -> float -> unit
val write_float_fast : Bi_outbuf.t -> float -> unit
val write_std_float_fast : Bi_outbuf.t -> float -> unit
val write_float_prec : int -> Bi_outbuf.t -> float -> unit
val write_std_float_prec : int -> Bi_outbuf.t -> float -> unit
val write_string : Bi_outbuf.t -> string -> unit
val write_intlit : Bi_outbuf.t -> string -> unit
val write_floatlit : Bi_outbuf.t -> string -> unit
val write_stringlit : Bi_outbuf.t -> string -> unit
val write_assoc : Bi_outbuf.t -> (string * json) list -> unit
val write_list : Bi_outbuf.t -> json list -> unit
val write_tuple : Bi_outbuf.t -> json list -> unit
val write_std_tuple : Bi_outbuf.t -> json list -> unit
val write_variant : Bi_outbuf.t -> string -> json option -> unit
val write_std_variant : Bi_outbuf.t -> string -> json option -> unit
val write_json : Bi_outbuf.t -> json -> unit
val write_std_json : Bi_outbuf.t -> json -> unit

JSON pretty-printing


val pretty_format : ?std:bool -> json -> Easy_format.t
Convert into a pretty-printable tree. See to_string for the role of the optional std argument.
See also Easy-format
val pretty_to_string : ?std:bool -> json -> string
Pretty-print into a string. See to_string for the role of the optional std argument.
val pretty_to_channel : ?std:bool -> Pervasives.out_channel -> json -> unit
Pretty-print to a channel. See to_string for the role of the optional std argument.