Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Zod has been a great boon to a project I've been working on. I get data from multiple sources where strong types cannot be generated and checking the schema of the response has caught a great number of errors early.

Another feature that I use intensively is transforming the response to parse JSON into more complex data types, e.g. dates but also project-specific types. In some situations, I also need to serialize these data types back into JSON. This is where Zod lacks most for my use-case. I cannot easily specify bidirectional transforms, instead I need to define two schemas (one for parsing, one for serializing) and only change the transforms. I have added type assertions that should catch any mistakes in this manual process, but it'd be great if I didn't have to keep these two schemas in sync.

Another comment mentioned @effect/schema [0], which apparently supports these encode/decode relationships. I'm excited to try it out.

[0] https://effect.website/docs/guides/schema/introduction



TypeBox[1] also supports bi-directional transforms.

[1]: https://github.com/sinclairzx81/typebox


Thank you for the pointer! I will certainly consider TypeBox as well when the time comes to migrate.


I use schema extensively and I can tell you it hits the sweet spot for your use case. We have lots of similar use cases.




Consider applying for YC's Fall 2025 batch! Applications are open till Aug 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: