package ppx_protocol_conv_json
Source file json.ml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69module Driver : Ppx_protocol_driver.Driver with type t = Yojson.Safe.t [@warning "-3"] = struct type t = Yojson.Safe.t [@warning "-3"] let to_string_hum t = Yojson.Safe.pretty_to_string t let of_list l = `List l let to_list = function `List l -> l | _ -> failwith "List expected" let is_list = function `List _ -> true | _ -> false let of_alist a = `Assoc a let to_alist = function `Assoc a -> a | _ -> failwith "Assoc expected" let is_alist = function `Assoc _ -> true | _ -> false let of_int i = `Int i let to_int = function `Int i -> i | _ -> failwith "Int expected" let of_int32 i = Int32.to_int i |> of_int let to_int32 t = to_int t |> Int32.of_int let of_int64 i = Int64.to_int i |> of_int let to_int64 t = to_int t |> Int64.of_int let of_nativeint i = Nativeint.to_int i |> of_int let to_nativeint t = to_int t |> Nativeint.of_int let of_float f = `Float f let to_float = function `Float f -> f | _ -> failwith "Float expected" let of_string s = `String s let to_string = function `String s -> s | _ -> failwith "String expected" let is_string = function `String _ -> true | _ -> false let of_char c = of_string (String.make 1 c) let to_char t = match to_string t with | s when String.length s = 1 -> s.[0] | _ -> failwith "Got string with length != 1 when reading type 'char'" let of_bool b = `Bool b let to_bool = function `Bool b -> b | _ -> failwith "Bool expected" let of_bytes b = `String (Bytes.to_string b) let to_bytes = function `String b -> Bytes.of_string b | _ -> failwith "Bytes expected" let null = `Null let is_null = function `Null -> true | _ -> false end include Ppx_protocol_driver.Make(Driver)(Ppx_protocol_driver.Default_parameters) module Make(P: Ppx_protocol_driver.Parameters) = Ppx_protocol_driver.Make(Driver)(P) module Yojson = struct include Make(struct include Ppx_protocol_driver.Default_parameters let omit_default_values = true let constructors_without_arguments_as_string = false let eager = true let strict = true end) let of_yojson_exn t = t let of_yojson t = Ok t let to_yojson t = t end (* Allow referencing Json.t in structures. *) let of_json_exn t = t let of_json t = Ok t let to_json t = t