package jsont
Install
dune-project
Dependency
Authors
Maintainers
Sources
sha512=6206f73a66cb170b560a72e58f70b9fb2c20397b9ab819dceba49b6602b9b79e47ba307e6910e61ca4694555c66fdcd7a17490afb99548e8f43845a5a88913e7
doc/jsont/Jsont/Base/index.html
Module Jsont.Base
Source
Mapping JSON base types.
Maps
The type for mapping JSON values of type 'a
to values of type 'b
.
val 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 anddoc
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 returnsJsont.Meta.none
.
These functions can be used to quickly devise dec
and enc
functions from standard OCaml conversion interfaces.
ignore
is the ignoring map. It ignores decodes and errors on encodes.
JSON types
null map
maps with map
JSON nulls represented by ()
to values of type 'a
. See also Jsont.null
.
bool map
maps with map
JSON booleans represented by bool
values to values of type 'a
. See also Jsont.bool
.
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
.
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
.
dec f
is a decoding function from f
. This assumes f
never fails.
dec f
is a decoding function from f
. Error _
values are given to Error.msg
, prefixed by kind:
(if specified).
dec f
is a decoding function from f
. Failure _
exceptions are catched and given to Error.msg
, prefixed by kind:
(if specified).
enc f
is an encoding function from f
. This assumes f
never fails.
enc_result f
is an encoding function from f
. Error _
values are given to Error.msg
, prefixed by kind:
(if specified).