| Json.Null -> 0
| Json.Bool b -> if b then 1 else 0
| Json.Int i -> Int64.to_int i
+ | Json.Float f -> int_of_float f
| Json.Array a ->
if Array.length a = 0 then
raise_unexpected_json_type "array" "int"
| Json.Null -> 0L
| Json.Bool b -> if b then 1L else 0L
| Json.Int i -> i
+ | Json.Float f -> Int64.of_float f
| Json.Array a ->
if Array.length a = 0 then
raise_unexpected_json_type "array" "int64"
let int64_to_json i = Json.Int i
+let float_of_json ?(permissive=false) j =
+ let strict = function
+ | Json.Float f -> f
+ | _ -> raise_unexpected_json_type (Json.string_of_type j) "float" in
+ let lenient = function
+ | Json.Null -> 0.0
+ | Json.Bool b -> if b then 1.0 else 0.0
+ | Json.Int i -> Int64.to_float i
+ | Json.Float f -> f
+ | Json.Array a ->
+ if Array.length a = 0 then
+ raise_unexpected_json_type "array" "float"
+ else
+ strict a.(0)
+ | _ -> raise_unexpected_json_type (Json.string_of_type j) "float" in
+ if not permissive then strict j else lenient j
+
+let float_to_json f = Json.Float f
+
let bool_of_json ?(permissive=false) j =
let strict = function
| Json.Bool b -> b
| Json.Null -> false
| Json.Bool b -> b
| Json.Int i -> i <> 0L
+ | Json.Float f -> f <> 0.0
| Json.Array a ->
if Array.length a = 0 then
raise_unexpected_json_type "array" "bool"
val int64_of_json: ?permissive:bool -> Json.t -> int64
val int64_to_json: int64 -> Json.t
+val float_of_json: ?permissive:bool -> Json.t -> float
+val float_to_json: float -> Json.t
+
val bool_of_json: ?permissive:bool -> Json.t -> bool
val bool_to_json: bool -> Json.t