package data-encoding

  1. Overview
  2. Docs

Module Data_encoding.JsonSource

Sourcetype json = [
  1. | `O of (string * json) list
  2. | `Bool of bool
  3. | `Float of float
  4. | `A of json list
  5. | `Null
  6. | `String of string
]

In memory JSON data, compatible with Ezjsonm.

Sourcetype t = json
Sourceval encoding : json Encoding.t

Encodes raw JSON data (BSON is used for binary).

Sourceval schema_encoding : schema Encoding.t

Encodes a JSON schema (BSON encoded for binary).

Sourceval schema : ?definitions_path:string -> 'a Encoding.t -> schema

Generate a schema from an encoding.

Sourceval construct : 't Encoding.t -> 't -> json

Construct a JSON object from an encoding.

Sourceval destruct : 't Encoding.t -> json -> 't

Destruct a JSON object into a value. Fail with an exception if the JSON object and encoding do not match..

JSON Error.

Sourcetype path = path_item list
Sourceand path_item = [
  1. | `Field of string
    (*

    A field in an object.

    *)
  2. | `Index of int
    (*

    An index in an array.

    *)
  3. | `Star
    (*

    Any / every field or index.

    *)
  4. | `Next
    (*

    The next element after an array.

    *)
]

A set of accessors that point to a location in a JSON object.

Sourceexception Cannot_destruct of path * exn

Exception raised by destructors, with the location in the original JSON structure and the specific error.

Sourceexception Unexpected of string * string

Unexpected kind of data encountered, with the expectation.

Sourceexception No_case_matched of exn list

Some union couldn't be destructed, with the reasons for each case.

Sourceexception Bad_array_size of int * int

Array of unexpected size encountered, with the expectation.

Sourceexception Missing_field of string

Missing field in an object.

Sourceexception Unexpected_field of string

Supernumerary field in an object.

Sourceval print_error : ?print_unknown:(Format.formatter -> exn -> unit) -> Format.formatter -> exn -> unit
Sourceval cannot_destruct : ('a, Format.formatter, unit, 'b) format4 -> 'a

Helpers for writing encoders.

Sourceval wrap_error : ('a -> 'b) -> 'a -> 'b
Sourceval from_string : string -> (json, string) result

Read a JSON document from a string.

Sourceval to_string : ?newline:bool -> ?minify:bool -> json -> string

Write a JSON document to a string. This goes via an intermediate buffer and so may be slow on large documents.

Sourceval pp : Format.formatter -> json -> unit