-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
v4: Schema key order is no longer preserved #4251
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
If we want to change the ordering in v4, I'd suggest that we preserve the input order rather than the shape order. If we want to keep the v3 behavior (probably the most conservative approach given the ecosystem size), I'd support that! |
I think we should preserve the shape order to maintain compatibility with Zod 3. |
Confirmed that this seems to happen during the |
In v3, when using
z.object
, the parsed return value kept the same key order as defined in the schema.v4 changes how ordering works - it now seems to group required and optional properties separately while maintaining order within each group. This approach preserves some ordering, but IMO it's worse to v3's approach of preserving schema order, or to an alternative approach that would maintain the original object order.
This is a significant behavior change, and I think it should at least be documented in the changelog at https://v4.zod.dev/v4/changelog
v4:
The text was updated successfully, but these errors were encountered: