package of_json

  1. Overview
  2. Docs
module Json : sig ... end
module Timestamp : sig ... end
module To_json : sig ... end
type 'a t = Json.t -> 'a
val run : 'a t -> Json.t -> 'a
include Core.Applicative.S with type 'a t := 'a t
val both : 'a t -> 'b t -> ('a * 'b) t
val (<*>) : ('a -> 'b) t -> 'a t -> 'b t
val (<*) : 'a t -> unit t -> 'a t
val (*>) : unit t -> 'a t -> 'a t
val apply : ('a -> 'b) t -> 'a t -> 'b t
val map2 : 'a t -> 'b t -> f:('a -> 'b -> 'c) -> 'c t
val map3 : 'a t -> 'b t -> 'c t -> f:('a -> 'b -> 'c -> 'd) -> 'd t
module Applicative_infix : sig ... end
include Core.Monad.S_without_syntax with type 'a t := 'a t
val (>>=) : 'a t -> ('a -> 'b t) -> 'b t
val (>>|) : 'a t -> ('a -> 'b) -> 'b t
module Monad_infix : sig ... end
val bind : 'a t -> f:('a -> 'b t) -> 'b t
val return : 'a -> 'a t
val map : 'a t -> f:('a -> 'b) -> 'b t
val join : 'a t t -> 'a t
val ignore_m : 'a t -> unit t
val all : 'a t list -> 'a list t
val all_unit : unit t list -> unit t
module Conv_failure : sig ... end
exception Of_json_conv_failed of Conv_failure.t
val annotate : ?location:string -> (Json.t -> 'a) -> Json.t -> 'a

Wrap a t such that if it raises an exception, additional json context information will be added to help in debugging

val using : string -> (Json.t -> 'a) -> Json.t -> 'a

Pull a value out of an object by key, and use another t to reify that. Raises if the key does not exist.

val using_opt : string -> (Json.t -> 'a) -> Json.t -> 'a option

Same as using, except returns an 'a option in the event the key is missing. If the key is present the value will be passed on to the 'a t, even if it is null. If the value might be null, you probably want option instead.

val (@.) : string -> (Json.t -> 'a) -> Json.t -> 'a

Operator of using for path traversal: "foo" @. "bar" @. int. Raises for non-objects.

val (@?) : string -> (Json.t -> 'a) -> Json.t -> 'a option

Operator of using_opt for path traversal with optional: "foo" @? "bar" @? int. Raises for non-objects.

val (@??) : string -> (Json.t -> 'a) -> Json.t -> 'a option

A combination of using_opt and option, to preserve the previous semantics of the @? operator that didn't distinguish between "key not present" and "key present but null".

Do not use this function. Use @? or option. This only exists so that we can change @? without breaking all (untestable) uses of it. If you see this function used in an existing parser, and you are in a position to test it, you should update it to use either @? or option.

If you think you want to use this function -- if a key is sometimes absent, sometimes present but null, sometimes present but not null, and there's no semantic difference between the first two scenarios -- then you should still write that down with an explicit Option.join and a comment and some tests, because that's a crazy thing.

val (@>) : (Json.t -> 'a) -> ('a -> 'b) -> Json.t -> 'b

Suffix map for converting: "foo" @. int @> Satoshi.of_int

val (>>>) : ('a -> 'b) -> ('b -> 'c) -> 'a -> 'c

Simple forward composition: int @> Foo.of_int >>> Bar.of_foo

Simple accessors by type. Will raise if the type does not match

val int : Json.t -> int
val float : Json.t -> float

Always returns a float even if the JSON does not have a literal '.' in it

val number : Json.t -> string

Returns the string representation of a JSON decimal number

val string : Json.t -> string
val bool : Json.t -> bool
val list : (Json.t -> 'a) -> Json.t -> 'a list
val option : (Json.t -> 'a) -> Json.t -> 'a option

Returns None if the value is `Null, and runs t otherwise

val number_string : Json.t -> string

Returns the string representation of either a JSON number or string.

Parse a JSON number or JSON string as an OCaml float or int. These are typically used as a last resort for inconsistent APIs.

val float_string : Json.t -> float
val int_string : Json.t -> int
val map_object : f:(string -> Json.t -> 'a) -> Json.t -> 'a list

Iterates over the keys of an object, passing each key to the ~f provided and running the resulting t on the value of that key. Collects all results as a list.

val safe : (Json.t -> 'a) -> Json.t -> 'a option

safe t runs a generic t but returns an option instead of an exception

val (<|>) : (Json.t -> 'a) -> (Json.t -> 'a) -> Json.t -> 'a

a <|> b first runs a, and if it fails, it runs b. Will raise if b raises.

val choice : (Json.t -> 'a) list -> Json.t -> 'a

choice [a; b; c] returns the first parser that succeeds, or raises with the last if all raise.

val as_sexp : (Core.Sexp.t -> 'a) -> Json.t -> 'a

A sexp embedded in a JSON string.

module Array_as_tuple : sig ... end
val tuple : 'a Array_as_tuple.t -> Json.t -> 'a

Turn an Array_as_tuple.t into a t that will expect a JSON array and parse each element as a different type. If any elements are left unparsed, an error is raised.

module Let_syntax : sig ... end
OCaml

Innovation. Community. Security.