package jsonoo

  1. Overview
  2. Docs

Module Jsonoo.DecodeSource

Sourcetype '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

Sourceval id : t decoder

Identity decoder returns its argument unchanged

Sourceval null : Ojs.t decoder

Only decode a JSON null

Sourceval bool : bool decoder

Decode true or false

Sourceval float : float decoder

Decode a JSON number

Sourceval int : int decoder

Decode a finite non-decimal JSON number

Sourceval string : string decoder

Decode a JSON string

Sourceval char : char decoder

Decode a single-character JSON string

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

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

Sourceval array : 'a decoder -> 'a array decoder

Decode a JSON array of values based on the given decoder

Sourceval list : 'a decoder -> 'a list decoder

Decode an JSON array of values as a list

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

Decode a 2-element JSON array with the given decoders

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

Decode a 2-element JSON array with the given decoders

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

Decode a 3-element JSON array with the given decoders

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

Decode a 4-element JSON array with the given decoders

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

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

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

Decode an element of a JSON dictionary with the decoder

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

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

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

Catch Decode_error, return None if raised

Sourceval try_default : 'a -> 'a decoder -> 'a decoder

Catch Decode_error, return a default value if raised

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

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

Sourceval either : 'a decoder -> 'a decoder -> 'a decoder

Try two decoders, raise Decode_error if neither succeed

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

Apply a function to the result of the decoder

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

Apply the decoder returned from the function

OCaml

Innovation. Community. Security.