package of_json

  1. Overview
  2. Docs
type 'a t

When a JSON API returns an Array of elements of different types as if it were a tuple, you can use this module to parse each element in a different manner and assert that you didn't miss any. Example:

let of_json =
  let open Of_json.Let_syntax in
  let%map_open parsed =
    "key" @. tuple Array_as_tuple.(
      [%map
        let a = shift @@ string
        and b = shift @@ number @> Int.of_string
        in (a, b)])
  in parsed
val shift : (Json.t -> 'a) -> 'a t

Wrap your normal Of_json combinators with shift to have them operate on the head of the list element, passing the tail on to the next combinator. Build up a t by combining these with apply or bind.

val drop_rest : unit t
module Let_syntax : sig ... end
OCaml

Innovation. Community. Security.