Key/value pairs of decoders for each object field.
How to display the name of the object being decoded in errors.
A decoder that validates and returns objects matching the specified structure
interface User {
firstName: string;
lastName: string;
age: number;
}
const userDecoder = JsonDecoder.object<User>(
{
firstName: JsonDecoder.string(),
lastName: JsonDecoder.string(),
age: JsonDecoder.number()
},
'User'
);
const json = {
firstName: 'John',
lastName: 'Doe',
age: 30
};
userDecoder.decode(json); // Ok<User>({value: {firstName: 'John', lastName: 'Doe', age: 30}})
Decoder for objects with specified field decoders.