The Standard Schema interface for this decoder.
Decodes a JSON object of type
The JSON object to decode
A Promise that resolves with the decoded value or rejects with an error message
Decodes a JSON object of type
The result of either onOk or onErr
If the decoder has succeeded, transforms the decoded value into something else
A new decoder that applies the transformation
// Decode a string, then transform it into a Date
const dateDecoder = JsonDecoder.string.map(stringDate => new Date(stringDate));
// Ok scenario
dateDecoder.decode('2018-12-21T18:22:25.490Z'); // Ok<Date>({value: Date(......)})
// Err scenario
dateDecoder.decode(false); // Err({error: 'false is not a valid string'})
A decoder that can validate and transform JSON data into strongly typed TypeScript values.