package jsonaf

  1. Overview
  2. Docs
type t = [
  1. | `Null
  2. | `False
  3. | `True
  4. | `String of Base.string
  5. | `Number of Base.string
  6. | `Object of (Base.string * t) Base.list
  7. | `Array of t Base.list
] constraint t = Jsonaf_kernel.t
val sexp_of_t : t -> Sexplib0.Sexp.t
val t_of_sexp : Sexplib0.Sexp.t -> t
val __t_of_sexp__ : Sexplib0.Sexp.t -> t

Note that we intentionally do not expose compare or equal functions for t. Objects in JSON are considered unordered, so two different representations of t may be unequal using the derived equal but the same according to the JSON spec.

val exactly_equal : t -> t -> Base.bool

exactly_equal checks equality including exact key order within objects

parse s parses a single JSON object from s. It is an error if s does not contain exactly one JSON object. See parse_many.

parse_many parses zero or more JSON objects from s.

Caveats: parse_many succeeds only if all JSON objects parse, and its error messages may be significantly worse than those from parse.

To get the well-formed objects up to the syntax error, and then a good error message, consider piping through jq -c, splitting on newlines, and then parsing each line with parse. But this is much slower than run_many.

include Base.Stringable.S with type t := t
val of_string : string -> t
val to_string : t -> string
val to_string_hum : t -> Base.string

human-readable output, indenting all fields/array elements by two spaces.

include Base.Pretty_printer.S with type t := t
val pp : Base.Formatter.t -> t -> unit
module Jsonafable : sig ... end
include Jsonafable.S with type t := t
val t_of_jsonaf : Jsonaf_kernel__.Type.t -> t
val jsonaf_of_t : t -> Jsonaf_kernel__.Type.t
module Parser : sig ... end
module Serializer : sig ... end
val index : Base.int -> t -> t Base.option
val index_exn : Base.int -> t -> t
val member : Base.string -> t -> t Base.option
val member_exn : Base.string -> t -> t
val bool : t -> Base.bool Base.option
val bool_exn : t -> Base.bool
val member_or_null : Base.string -> t -> t

Same as member, but returns `Null instead of None if the member isn't present. This function is useful when migrating from Yojson, as it is equivalent to Yojson.Safe.Util.member. If writing new code using Jsonaf, you should probably avoid it. Consider using Of_json instead.

If t is a json number but not parseable as a float, float t returns None. Similarly int t will return None if the number is not parseable as an int.

val int : t -> Base.int Base.option
val int_exn : t -> Base.int
val float : t -> Base.float Base.option
val float_exn : t -> Base.float
val string : t -> Base.string Base.option
val string_exn : t -> Base.string
val list : t -> t Base.list Base.option
val list_exn : t -> t Base.list
val assoc_list : t -> (Base.string * t) Base.list Base.option

If t is an object, return the association list between keys and values. Otherwise, return None. O(1).

val assoc_list_exn : t -> (Base.string * t) Base.list

If t is an object, return the association list between keys and values. Otherwise, raise. O(1).

If t is an object, return the keys of that object. Otherwise, return None. O(n).

val keys_exn : t -> Base.string Base.list

If t is an object, return the keys of that object. Otherwise, raise. O(n).

val jsonaf_of_unit : Base.unit -> Jsonaf_kernel.t
val jsonaf_of_bool : Base.bool -> Jsonaf_kernel.t
val jsonaf_of_string : Base.string -> Jsonaf_kernel.t
val jsonaf_of_bytes : Base.bytes -> Jsonaf_kernel.t
val jsonaf_of_char : Base.char -> Jsonaf_kernel.t
val jsonaf_of_int : Base.int -> Jsonaf_kernel.t
val jsonaf_of_float : Base.float -> Jsonaf_kernel.t
val jsonaf_of_int32 : Base.int32 -> Jsonaf_kernel.t
val jsonaf_of_int64 : Base.int64 -> Jsonaf_kernel.t
val jsonaf_of_nativeint : Base.nativeint -> Jsonaf_kernel.t
val jsonaf_of_ref : ('a -> Jsonaf_kernel.t) -> 'a Base.ref -> Jsonaf_kernel.t
val jsonaf_of_lazy_t : ('a -> Jsonaf_kernel.t) -> 'a lazy_t -> Jsonaf_kernel.t
val jsonaf_of_option : ('a -> Jsonaf_kernel.t) -> 'a Base.option -> Jsonaf_kernel.t
val jsonaf_of_list : ('a -> Jsonaf_kernel.t) -> 'a Base.list -> Jsonaf_kernel.t
val jsonaf_of_array : ('a -> Jsonaf_kernel.t) -> 'a Base.array -> Jsonaf_kernel.t
val jsonaf_of_hashtbl : ('a -> Jsonaf_kernel.t) -> ('b -> Jsonaf_kernel.t) -> ('a, 'b) Caml.Hashtbl.t -> Jsonaf_kernel.t
val unit_of_jsonaf : Jsonaf_kernel.t -> Base.unit
val bool_of_jsonaf : Jsonaf_kernel.t -> Base.bool
val string_of_jsonaf : Jsonaf_kernel.t -> Base.string
val bytes_of_jsonaf : Jsonaf_kernel.t -> Base.bytes
val char_of_jsonaf : Jsonaf_kernel.t -> Base.char
val int_of_jsonaf : Jsonaf_kernel.t -> Base.int
val float_of_jsonaf : Jsonaf_kernel.t -> Base.float
val int32_of_jsonaf : Jsonaf_kernel.t -> Base.int32
val int64_of_jsonaf : Jsonaf_kernel.t -> Base.int64
val nativeint_of_jsonaf : Jsonaf_kernel.t -> Base.nativeint
val ref_of_jsonaf : (Jsonaf_kernel.t -> 'a) -> Jsonaf_kernel.t -> 'a Base.ref
val lazy_t_of_jsonaf : (Jsonaf_kernel.t -> 'a) -> Jsonaf_kernel.t -> 'a lazy_t
val option_of_jsonaf : (Jsonaf_kernel.t -> 'a) -> Jsonaf_kernel.t -> 'a Base.option
val list_of_jsonaf : (Jsonaf_kernel.t -> 'a) -> Jsonaf_kernel.t -> 'a Base.list
val array_of_jsonaf : (Jsonaf_kernel.t -> 'a) -> Jsonaf_kernel.t -> 'a Base.array
val hashtbl_of_jsonaf : (Jsonaf_kernel.t -> 'a) -> (Jsonaf_kernel.t -> 'b) -> Jsonaf_kernel.t -> ('a, 'b) Caml.Hashtbl.t