package jsonaf

  1. Overview
  2. Docs
A library for parsing, manipulating, and serializing data structured as JSON

Install

Dune Dependency

Authors

Maintainers

Sources

jsonaf-v0.16.0.tar.gz
sha256=0c85230d47dcc80c428ad82e0f2cb0ecbb5048129eaa036aeeb4cfb8d9d2063f

doc/jsonaf/Jsonaf/index.html

Module JsonafSource

Sourcetype 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
Sourceval sexp_of_t : t -> Sexplib0.Sexp.t
Sourceval t_of_sexp : Sexplib0.Sexp.t -> t
Sourceval __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.

Sourceval 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
Sourceval of_string : string -> t
Sourceval to_string : t -> string
Sourceval 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
Sourceval pp : Base.Formatter.t -> t -> unit
Sourcemodule Jsonafable : sig ... end
include Jsonafable.S with type t := t
Sourceval t_of_jsonaf : Jsonaf_kernel__.Type.t -> t
Sourceval jsonaf_of_t : t -> Jsonaf_kernel__.Type.t
Sourcemodule Parser : sig ... end
Sourcemodule Serializer : sig ... end
Sourceval index : Base.int -> t -> t Base.option
Sourceval index_exn : Base.int -> t -> t
Sourceval member : Base.string -> t -> t Base.option
Sourceval member_exn : Base.string -> t -> t
Sourceval bool_exn : t -> Base.bool
Sourceval 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.

Sourceval int_exn : t -> Base.int
Sourceval float_exn : t -> Base.float
Sourceval string_exn : t -> Base.string
Sourceval list_exn : t -> t Base.list
Sourceval 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).

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

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