camlspotter avatar camlspotter committed 4fafae1

move to tiny_json

Comments (0)

Files changed (4)

 name="bitbucket"
 version="0.0.0"
 description="Bitbucket API for OCaml"
-requires="meta_conv,json-wheel,spotlib,curl,unix,sexplib"
+requires="tiny_json_conv,spotlib,curl,sexplib"
 archive(byte)="bitbucket.cmo"
 archive(native)="bitbucket.cmx"
 linkopts = ""
 
 OCAMLPACKS[] =
     curl
-    json-wheel
+    tiny_json_conv
     sexplib
-    meta_conv
     spotlib
 
 OCAMLFLAGS = -annot -w A-4-9-39 
 FILES[] =
     xcurl
     common
-    json_wrap
     api
     hg
 
 open Common
-open Json_wrap
+open Tiny_json
+open Json_conv
 open Meta_conv.Conv
-open Json_conv
 open Sexplib.Conv
 
 module Json = struct
-  include Json_wrap.Json
-  let sexp_of_t j = Sexplib.Sexp.Atom (Json_io.string_of_json j)
+  include Json
+  let sexp_of_t j = Sexplib.Sexp.Atom (Json.show j)
   let t_of_sexp = function
-    | Sexplib.Sexp.Atom s -> Json_io.json_of_string s
+    | Sexplib.Sexp.Atom s -> Json.parse s
     | _ -> assert false
 end
 
     and resp = repo list with conv(json)
 
     let get ~user ~password = 
-      resp_of_json (Json_io.json_of_string (Curl.get_string (fun h ->
+      resp_of_json (Json.parse (Curl.get_string (fun h ->
         h#set_url "https://api.bitbucket.org/1.0/user/repositories/";
         h#set_userpwd (Printf.sprintf "%s:%s" user password))))
   end
       h#set_url "https://api.bitbucket.org/1.0/user";
       h#set_userpwd (Printf.sprintf "%s:%s" user password))
     in
-    try resp_of_json_exn (Json_io.json_of_string s) with e -> 
+    try resp_of_json_exn (Json.parse s) with e -> 
       prerr_endline (Printexc.to_string e);
       prerr_endline s;
       raise e

json_wrap.ml

-module Json = struct
-  type t = Json_type.json_type =
-      | Object of (string * t) list
-      | Array of t list
-      | String of string
-      | Int of int
-      | Bigint of string
-      | Float of float
-      | Bool of bool
-      | Null
-end
-
-module Json_conv = struct
-  open Printf
-  open Meta_conv.Conv
-  open Json
-  
-  (* encoders ***************************************************************)
-  
-  (* pretty normal. nothing to say specially *)
-  
-  module Encode = struct
-    let tuple ts       = Array ts
-    let variant tag = function
-      | [] -> String tag
-      | ts -> Object [tag, Array ts]
-    let record tag_ts  = Object tag_ts
-  end
-  
-  let json_of_int n       = Int n
-  let json_of_int32 n     = Bigint (Int32.to_string n)
-  let json_of_int64 n     = Bigint (Int64.to_string n)
-  let json_of_nativeint n = Bigint (Nativeint.to_string n)
-  let json_of_char c      = String (String.make 1 c)
-  let json_of_string s    = String s
-  let json_of_float n     = Float n
-  let json_of_list f xs   = Array (List.map f xs)
-  let json_of_array f xs  = Array (List.map f (Array.to_list xs))
-  let json_of_bool b      = Bool b
-  let json_of_lazy_t f v  = f (Lazy.force v)
-  let json_of_unit ()     = Null
-  let json_of_option f    = function
-    | None -> Null
-    | Some v -> f v
-    
-  (* decoders ***************************************************************)
-  
-  (* complex
-  
-     Do we really need addresses?
-  
-  *)
-  
-  module Decode = Make_Decode_Adrs(struct
-    type t = Json.t
-  
-    let tuple = function 
-      | Array ts -> ts
-      | _ -> failwith "Array expected for array"
-  
-    let variant = function 
-      | String tag -> tag, [] 
-      | Object [tag, Array ts] -> tag, ts
-      | _ -> failwith "Object expected for variant"
-  
-    let record = function
-      | Object alist -> alist
-      | _ -> failwith "Object expected for record"
-  end)
-  
-  exception Error of Json.t error
-  
-  type 'a decoder = ('a, Json.t) Meta_conv.Conv.decoder
-  
-  let errorf v adrs fmt = 
-    kprintf (fun s -> `Error (Primitive_decoding_failure s, v, adrs)) fmt
-  
-  let string_of_json ?(adrs=Address.top) = function
-    | String s -> `Ok s
-    | v -> errorf v adrs "string_of_json: String expected"
-  
-  let char_of_json ?(adrs=Address.top) = function
-    | String s when String.length s = 1 -> `Ok s.[0]
-    | v -> errorf v adrs "char_of_json: a char expected"
-  
-  let int_check name min max conv ?(adrs=Address.top) v = match v with
-    | Int n -> `Ok (conv (float_of_int n))
-    | Bigint n -> (* only works inside the float expressive power *)
-        begin match integer_of_float min max conv (float_of_string n) with
-        | `Ok v -> `Ok v
-        | `Error s -> errorf v adrs "%s_of_json: %s" name s
-        end
-    | Float n -> 
-        begin match integer_of_float min max conv n with
-        | `Ok v -> `Ok v
-        | `Error s -> errorf v adrs "%s_of_json: %s" name s
-        end
-    | _ -> errorf v adrs "%s_of_json: Number expected" name
-  
-  let int_of_json =
-    int_check "int" (float min_int) (float max_int) int_of_float
-  
-  let int64_of_json =
-    let open Int64 in
-    int_check "int64" (to_float min_int) (to_float max_int) of_float
-        
-  let int32_of_json =
-    let open Int32 in
-    int_check "int32" (to_float min_int) (to_float max_int) of_float
-        
-  let nativeint_of_json = 
-    let open Nativeint in
-    int_check "nativeint" (to_float min_int) (to_float max_int) of_float
-        
-  let float_of_json ?(adrs=Address.top) = function
-    | Float n -> `Ok n
-    | Int n -> `Ok (float_of_int n)
-    | Bigint n -> `Ok (float_of_string n)
-    | n -> errorf n adrs "float_of_json: Number expected"
-  
-  let bool_of_json ?(adrs=Address.top) = function
-    | Bool b -> `Ok b
-    | v -> errorf v adrs "bool_of_json: Bool expected"
-  
-  let unit_of_json ?(adrs=Address.top) = function
-    | Null -> `Ok ()
-    | v -> errorf v adrs "unit_of_json: Null expected"
-    
-  let list_of_json f = 
-    generic_list_of (function Array xs -> Some xs | _ -> None) f
-  
-  let array_of_json f = 
-    generic_array_of (function Array xs -> Some xs | _ -> None) f
-  
-  let option_of_json f = generic_option_of 
-    (function Null -> true | _ -> false)
-    f
-  
-  let lazy_t_of_json = generic_lazy_t_of
-end
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.