Module Jsonoo.Decode

type 'a decoder = t -> 'a

The type for decoder functions which turn JSON into an OCaml value

functions that are unsuccessful in decoding the JSON raise Decode_error

val id : t decoder

Identity decoder returns its argument unchanged

val null : Ojs.t decoder

Only decode a JSON null

val bool : bool decoder

Decode true or false

val float : float decoder

Decode a JSON number

val int : int decoder

Decode a finite non-decimal JSON number

val string : string decoder

Decode a JSON string

val char : char decoder

Decode a single-character JSON string

val nullable : 'a decoder -> 'a option decoder

Transform a decoder so it decodes nulls as None and other decoded values as Some

val array : 'a decoder -> 'a array decoder

Decode a JSON array of values based on the given decoder

val list : 'a decoder -> 'a list decoder

Decode an JSON array of values as a list

val pair : 'a decoder -> 'b decoder -> ('a * 'b) decoder

Decode a 2-element JSON array with the given decoders

val tuple2 : 'a decoder -> 'b decoder -> ('a * 'b) decoder

Decode a 2-element JSON array with the given decoders

val tuple3 : 'a decoder -> 'b decoder -> 'c decoder -> ('a * 'b * 'c) decoder

Decode a 3-element JSON array with the given decoders

val tuple4 : 'a decoder -> 'b decoder -> 'c decoder -> 'd decoder -> ('a * 'b * 'c * 'd) decoder

Decode a 4-element JSON array with the given decoders

val dict : 'a decoder -> (string, 'a) Stdlib.Hashtbl.t decoder

Decode a JSON dictionary as a hash table of strings to decoded values

val field : string -> 'a decoder -> 'a decoder

Decode an element of a JSON dictionary with the decoder

val at : string list -> 'a decoder -> 'a decoder

Follow a list of field names and decode the final element with the decoder

val try_optional : 'a decoder -> 'a option decoder

Catch Decode_error, return None if raised

val try_default : 'a -> 'a decoder -> 'a decoder

Catch Decode_error, return a default value if raised

val any : 'a decoder list -> 'a decoder

Try a list of decoders until one succeeds, raise Decode_error if none succeed

val either : 'a decoder -> 'a decoder -> 'a decoder

Try two decoders, raise Decode_error if neither succeed

val map : ('a -> 'b) -> 'a decoder -> 'b decoder

Apply a function to the result of the decoder

val bind : ('a -> 'b decoder) -> 'a decoder -> 'b decoder

Apply the decoder returned from the function