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

val parse : Base.string -> t Base.Or_error.t

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.

val parse_many : Base.string -> t Base.list Base.Or_error.t

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).

val keys : t -> Base.string Base.list Base.option

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).

OCaml

Innovation. Community. Security.