// Example where the JSON has `first_name`, but our TypeScript property is `firstName`
interface User { firstName: string; lastName: string; age: number }
const decoders: DecoderObject<User> = {
firstName: { fromKey: 'first_name', decoder: JsonDecoder.string() },
lastName: { fromKey: 'last_name', decoder: JsonDecoder.string() },
age: JsonDecoder.number()
};
Represents an object that maps properties of a TypeScript type
Tto decoders used to validate raw JSON values. Each property may either be aDecoder<T[P]>(decoding a field from the same key in the input JSON) or an object withfromKeyanddecoderto decode from a different input key.The
fromKeyoption is useful when your TypeScript property name differs from the incoming JSON key (for example, snake_case JSON keys mapped to camelCase TypeScript properties). Errors reported still reference the TypeScript property name (the key ofDecoderObject).