package jsonaf
-
jsonaf.kernel
Legend:
Library
Module
Module type
Parameter
Class
Class type
Library
Module
Module type
Parameter
Class
Class type
type t = [
| `Null
| `False
| `True
| `String of Base.string
| `Number of Base.string
| `Object of (Base.string * t) Base.list
| `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.
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
.
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 member : Base.string -> t -> t Base.option
val member_exn : Base.string -> t -> t
val bool : t -> Base.bool Base.option
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 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 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).
module Export : Jsonaf_kernel.Conv.Primitives