package jsont

  1. Overview
  2. Docs
Declarative JSON data manipulation for OCaml

Install

dune-project
 Dependency

Authors

Maintainers

Sources

jsont-0.2.0.tbz
sha512=6206f73a66cb170b560a72e58f70b9fb2c20397b9ab819dceba49b6602b9b79e47ba307e6910e61ca4694555c66fdcd7a17490afb99548e8f43845a5a88913e7

doc/jsont/Jsont/Base/index.html

Module Jsont.BaseSource

Mapping JSON base types.

Maps

Sourcetype ('a, 'b) map

The type for mapping JSON values of type 'a to values of type 'b.

Sourceval map : ?kind:string -> ?doc:string -> ?dec:(Meta.t -> 'a -> 'b) -> ?enc:('b -> 'a) -> ?enc_meta:('b -> Meta.t) -> unit -> ('a, 'b) map

map ~kind ~doc ~dec ~enc ~enc_meta () maps JSON base types represented by value of type 'a to values of type 'b with:

  • kind names the entities represented by the map and doc documents them. Both default to "".
  • dec is used to decode values of type 'a to values of type 'b. Can be omitted if the map is only used for encoding, the default unconditionally errors.
  • enc is used to encode values of type 'b to values of type 'a. Can be omitted if the map is only used for decoding, the default unconditionally errors.
  • enc_meta is used to recover JSON metadata (source text layout information) from a value to encode. The default unconditionnaly returns Jsont.Meta.none.

These functions can be used to quickly devise dec and enc functions from standard OCaml conversion interfaces.

Sourceval id : ('a, 'a) map

id is the identity map.

Sourceval ignore : ('a, unit) map

ignore is the ignoring map. It ignores decodes and errors on encodes.

JSON types

Sourceval null : (unit, 'a) map -> 'a t

null map maps with map JSON nulls represented by () to values of type 'a. See also Jsont.null.

Sourceval bool : (bool, 'a) map -> 'a t

bool map maps with map JSON booleans represented by bool values to values of type 'a. See also Jsont.bool.

Sourceval number : (float, 'a) map -> 'a t

number map maps with map JSON nulls or numbers represented by float values to values of type 'a. The float representation decodes JSON nulls to Float.nan and lossily encodes any non-finite to JSON null (explanation). See also Jsont.number.

Sourceval string : (string, 'a) map -> 'a t

string map maps with map unescaped JSON strings represented by UTF-8 encoded string values to values of type 'a. See also Jsont.string.

Decoding and encoding functions

These function create suitable dec and enc functions to give to map from standard OCaml conversion interfaces. See also Jsont.of_of_string.

Sourceval dec : ('a -> 'b) -> Meta.t -> 'a -> 'b

dec f is a decoding function from f. This assumes f never fails.

Sourceval dec_result : ?kind:string -> ('a -> ('b, string) result) -> Meta.t -> 'a -> 'b

dec f is a decoding function from f. Error _ values are given to Error.msg, prefixed by kind: (if specified).

Sourceval dec_failure : ?kind:string -> ('a -> 'b) -> Meta.t -> 'a -> 'b

dec f is a decoding function from f. Failure _ exceptions are catched and given to Error.msg, prefixed by kind: (if specified).

Sourceval enc : ('b -> 'a) -> 'b -> 'a

enc f is an encoding function from f. This assumes f never fails.

Sourceval enc_result : ?kind:string -> ('b -> ('a, string) result) -> 'b -> 'a

enc_result f is an encoding function from f. Error _ values are given to Error.msg, prefixed by kind: (if specified).

Sourceval enc_failure : ?kind:string -> ('b -> 'a) -> 'b -> 'a

enc_failure f is an encoding function from f. Failure _ exceptions are catched and given to Error.msg, prefixed by kind: (if specified).

OCaml

Innovation. Community. Security.