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
.
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.
val encode :
?format:Jsont.format ->
'a Jsont.t ->
'a ->
(Jstr.t, Jv.Error.t) Stdlib.result
encode t v
encodes v
to JSON according to t
. format
specifies how the JSON is formatted, defaults to Jsont.format.Minify
. The Jsont.format.Layout
format is unsupported, Jsont.format.Indent
is used instead.
val encode' :
?format:Jsont.format ->
'a Jsont.t ->
'a ->
(Jstr.t, Jsont.Error.t) Stdlib.result
encode'
is like encode
but preserves the error structure. format
specifies how the JSON is formatted, defaults to Jsont.format.Minify
. The Jsont.format.Layout
format is unsupported, Jsont.format.Indent
is used instead.
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.
val recode :
?format:Jsont.format ->
'a Jsont.t ->
Jstr.t ->
(Jstr.t, Jv.Error.t) Stdlib.result
val recode' :
?format:Jsont.format ->
'a Jsont.t ->
Jstr.t ->
(Jstr.t, Jsont.Error.t) Stdlib.result
val recode_jv : 'a Jsont.t -> Jv.t -> (Jv.t, Jv.Error.t) Stdlib.result
val recode_jv' : 'a Jsont.t -> Jv.t -> (Jv.t, Jsont.Error.t) Stdlib.result
recode
is decode_jv'
followed by encode_jv'
.