Legend:
Library
Module
Module type
Parameter
Class
Class type
Library
Module
Module type
Parameter
Class
Class type
module Json : sig ... end
module Timestamp : sig ... end
module To_json : sig ... end
type 'a t = Json.t -> 'a
include Core.Applicative.S with type 'a t := 'a t
module Applicative_infix : sig ... end
include Core.Monad.S_without_syntax with type 'a t := 'a t
t >>= f
returns a computation that sequences the computations represented by two monad elements. The resulting computation first does t
to yield a value v
, and then runs the computation returned by f v
.
module Monad_infix : sig ... end
val return : 'a -> 'a t
return v
returns the (trivial) computation that returns v.
ignore_m t
is map t ~f:(fun _ -> ())
. ignore_m
used to be called ignore
, but we decided that was a bad name, because it shadowed the widely used Stdlib.ignore
. Some monads still do let ignore = ignore_m
for historical reasons.
module Conv_failure : sig ... end
exception Of_json_conv_failed of Conv_failure.t
Wrap a t
such that if it raises an exception, additional json context information will be added to help in debugging
Pull a value out of an object by key, and use another t
to reify that. Raises if the key does not exist.
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.
Operator of using
for path traversal: "foo" @. "bar" @. int. Raises for non-objects.
Operator of using_opt
for path traversal with optional: "foo" @? "bar" @? int. Raises for non-objects.
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.
Suffix map
for converting: "foo" @. int @> Satoshi.of_int
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
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
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.
safe t
runs a generic t
but returns an option instead of an exception
a <|> b
first runs a
, and if it fails, it runs b
. Will raise if b
raises.
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