A decoder is a function that takes a JSON value and transforms it into an F# value.

Example of a successful decoder:

Decode.fromString Decode.int "1"

Returns:

Ok 1

Example of a failed decoder:

In case of an error, a decoder returns an helpful errors explaining:

  1. Where the error happened in the JSON using the JSONPath syntax.

    You can use tools like JSONPath Online Evaluator to explore your JSON

  2. What was expected

  3. What was received

Decode.fromString Decode.int "\"maxime\""

Returns:

Error at: `$`
Expecting an int but instead got: "maxime"