Module Jsont_brr

JavaScript support.

Note. These functions incur a bit of overhead but should work fast enough for medium sized structures. Get in touch if you run into problems, some improvements may be possible.

The JSON functions use JavaScript's JSON.parse and JSON.stringify to convert to JavaScript values which are then converted with decode_jv and encode_jv.

Decode

val decode : 'a Jsont.t -> Jstr.t -> ('a, Jv.Error.t) Stdlib.result

decode t s decodes the JSON data s according to t.

val decode' : 'a Jsont.t -> Jstr.t -> ('a, Jsont.Error.t) Stdlib.result

decode' t s is like decode but preserves the error structure.

val decode_jv : 'a Jsont.t -> Jv.t -> ('a, Jv.Error.t) Stdlib.result

decode_jv t v decodes the JavaScript value v according to t.

val decode_jv' : 'a Jsont.t -> Jv.t -> ('a, Jsont.Error.t) Stdlib.result

decode_jv' is like decode_jv' but preserves the error structure.

Encode

val encode : 'a Jsont.t -> 'a -> (Jstr.t, Jv.Error.t) Stdlib.result

encode t v encodes v to JSON according to t.

val encode' : 'a Jsont.t -> 'a -> (Jstr.t, Jsont.Error.t) Stdlib.result

encode' is like encode but preserves the error structure.

val encode_jv : 'a Jsont.t -> 'a -> (Jv.t, Jv.Error.t) Stdlib.result

encode_jv t v encodes v to a JavaScript value according to t.

val encode_jv' : 'a Jsont.t -> 'a -> (Jv.t, Jsont.Error.t) Stdlib.result

encode_jv' is like encode_jv but preserves the error structure.