package b0
Install
dune-project
Dependency
Authors
Maintainers
Sources
sha512=00a6868b4dfa34565d0141b335622a81a0e8d5b9e3c6dfad025dabfa3df2db2a1302b492953bbbce30c3a4406c324fcec25250a00b38f6d18a69e15605e3b07e
doc/b0_b00_kit/B00_serialk_json/Json/index.html
Module B00_serialk_json.Json
JSON text
type loc = B00_serialk_text.Tloc.tThe type for text locations.
val loc_nil : locloc_nil is an invalid input location.
and t = [ | `Null of loc| `Bool of bool * loc| `Float of float * loc| `String of string * loc| `A of t list * loc| `O of mem list * loc
]The type for generic JSON text representations.
Constructors
val null : tnull is `Null loc_nil.
val bool : bool -> tbool b is `Bool (b, loc_nil).
val float : float -> tfloat b is `Float (f, loc_nil).
val string : string -> tstring s is `String (s, loc_nil).
Accessors
val to_null : t -> (unit, string) Stdlib.resultto_null j extracts a null from j. If j is not a null an error with the location formatted according to Tloc.pp is returned.
val to_bool : t -> (bool, string) Stdlib.resultto_bool j extracts a bool from j. If j is not a bool an error with the location formatted according to Tloc.pp is returned.
val to_float : t -> (float, string) Stdlib.resultto_float j extracts a float from j. If j is not a float an error with the location formatted according to Tloc.pp is returned.
to_array j extracts a array from j. If j is not a array an error with the location formatted according to Tloc.pp is returned.
to_obj j extracts a array from j. If j is not a array an error with the location formatted according to Tloc.pp is returned.
val get_float : t -> floatget_float j is like to_float but raises Invalid_argument if j is not a float.
val get_string : t -> stringget_string j is like to_string but raises Invalid_argument if j is not a string.
get_array j is like to_array but raises Invalid_argument if j is not a array.
get_obj j is like to_obj but raises Invalid_argument if j is not a array.
Formatters
val pp : Stdlib.Format.formatter -> t -> unitpp formats JSON text.
Warning. Assumes all OCaml strings in the formatted value are UTF-8 encoded.
Codec
val of_string :
?file:B00_serialk_text.Tloc.fpath ->
string ->
(t, string) Stdlib.resultof_string s parses JSON text from s according to RFC8259 with the following limitations:
- Numbers are parsed with
string_of_floatwhich is not compliant. - TODO Unicode escapes are left unparsed (this will not round trip with
to_string).
Note. All OCaml strings returned by this function are UTF-8 encoded.