Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Of_json.Array_as_tuple
SourceWhen 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
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
.