zod
zod copied to clipboard
Feature Proposal: Allow Support for alternative field names
What
Extend zod by a possibility to provide alternative or secondary field names. Those secondary field names are considered when parsing an object and the primary field name is not found in an object. This would be a great addition to ease renaming fields in a schema without backward incompatible changes
This could look like this
const schema = z.object({
myField: z.string().secondaryName('myOldField'),
});
Parsing the following objects would result in the same output
schema.parse({myField:'some'}) // result is {myField:'some'}
schema.parse({myOldField:'some'}) // result is {myField:'some'}