Source

ocaml-bitbucket / xjson.ml

camlspotter ed5011a 





camlspotter b80a06c 
camlspotter ed5011a 


camlspotter b80a06c 
camlspotter ed5011a 














camlspotter b80a06c 
camlspotter ed5011a 







open Spotlib.Spot
open Meta_conv.Result.Open
open Tiny_json

(* CR jfuruse: can be shared with other json apps *)
let ocaml_of_t : Json.t Ocaml_conv.encoder = fun j -> Ocaml.String (Json.show j)
let t_of_ocaml : Json.t Ocaml_conv.decoder = fun ?(trace=[]) o ->
  try match o with
  | Ocaml.String s -> `Ok (Json.parse s)
  | _ -> failwith "Ocaml.String expected"
  with e -> `Error (Meta_conv.Error.Exception e, o, trace)

let parse s = try `Ok (Json.parse s) with e -> `Error (`Json_parse e)

(* CR jfuruse: can be shared with other json apps *)
module Error = struct
  open Format

  let wrap_json_conv (convf : 'a Json_conv.decoder) s = match convf s with
    | `Ok v -> `Ok v
    | `Error e -> `Error (`Json_conv e)

  let format ppf = function
    | `Http (n, _err) -> fprintf ppf "HTTP Error %d@." n
    | `Json_parse exn -> fprintf ppf "Error at Json parse: %s@." (Printexc.to_string exn)
    | `Other exn      -> fprintf ppf "Error: %s@." (Printexc.to_string exn)
    | `Json_conv e -> Json_conv.format_full_error Json.format Format.stderr e 

  let from_Ok = function
    | `Ok v -> v
    | `Error e -> failwith (Format.sprintf "%a" format e)
end

let curl_get_and_parse (convf : 'a Json_conv.decoder) curlf = 
  Xcurl.get_string curlf >>= parse >>= Error.wrap_json_conv convf
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.