package of_json

  1. Overview
  2. Docs
A friendly applicative interface for Jsonaf.

Install

Dune Dependency

Authors

Maintainers

Sources

v0.17.0.tar.gz
sha256=19351755bd4c2f72968a712b730659f89edda7be23151015d5080e79146597c7

doc/of_json/Of_json/index.html

Module Of_jsonSource

Sourcemodule Json : sig ... end
Sourcemodule Timestamp : sig ... end
Sourcemodule To_json : sig ... end
Sourcetype 'a t = Json.t -> 'a
Sourceval run : 'a t -> Json.t -> 'a
include Core.Applicative.S with type 'a t := 'a t
Sourceval both : 'a t -> 'b t -> ('a * 'b) t
Sourceval (<*>) : ('a -> 'b) t -> 'a t -> 'b t

same as apply

Sourceval (<*) : 'a t -> unit t -> 'a t
Sourceval (*>) : unit t -> 'a t -> 'a t
Sourceval apply : ('a -> 'b) t -> 'a t -> 'b t
Sourceval map2 : 'a t -> 'b t -> f:('a -> 'b -> 'c) -> 'c t
Sourceval map3 : 'a t -> 'b t -> 'c t -> f:('a -> 'b -> 'c -> 'd) -> 'd t
Sourcemodule Applicative_infix : sig ... end
include Core.Monad.S_without_syntax with type 'a t := 'a t
Sourceval (>>=) : 'a t -> ('a -> 'b t) -> 'b 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.

Sourceval (>>|) : 'a t -> ('a -> 'b) -> 'b t

t >>| f is t >>= (fun a -> return (f a)).

Sourcemodule Monad_infix : sig ... end
Sourceval bind : 'a t -> f:('a -> 'b t) -> 'b t

bind t ~f = t >>= f

Sourceval return : 'a -> 'a t

return v returns the (trivial) computation that returns v.

Sourceval map : 'a t -> f:('a -> 'b) -> 'b t

map t ~f is t >>| f.

Sourceval join : 'a t t -> 'a t

join t is t >>= (fun t' -> t').

Sourceval ignore_m : 'a t -> unit t

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.

Sourceval all : 'a t list -> 'a list t
Sourceval all_unit : unit t list -> unit t

Like all, but ensures that every monadic value in the list produces a unit value, all of which are discarded rather than being collected into a list.

Sourcemodule Conv_failure : sig ... end
Sourceexception Of_json_conv_failed of Conv_failure.t
Sourceval 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

Sourceval 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.

Sourceval 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.

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

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

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

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

Sourceval (@??) : 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.

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

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

Sourceval (>>>) : ('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

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

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

Sourceval number : Json.t -> string

Returns the string representation of a JSON decimal number

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

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

Sourceval 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.

Sourceval float_string : Json.t -> float
Sourceval int_string : Json.t -> int
Sourceval 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.

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

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

Sourceval (<|>) : (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.

Sourceval 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.

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

A sexp embedded in a JSON string.

Sourcemodule Array_as_tuple : sig ... end
Sourceval 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.

Sourcemodule Let_syntax : sig ... end
OCaml

Innovation. Community. Security.