Skip to content

Zod schema serialize/deserialize #2030

Answered by StefanTerdell
valerii15298 asked this question in Q&A
Discussion options

You must be logged in to vote

This has come up a few times in json-schema-to-zod, which along with its counterpart probably is the closest you'll get to what you're looking for. There has been a couple of requests for a way to do essentially what you're describing here - turn a JSON schema into a Zod schema at runtime. My stance has always been that it doesn't make much sense to turn a perfectly good JSON schema into a Zod schema due to possibly getting weaker validation caused by translation errors or limitations. For instance, there is no (sane) way to deserialize a preprocess callback, and JSTZ even utilizes superRefine to bridge the gap of Zods missing equivalent of the oneOf-keyword! 🤪 Since type inference wouldn…

Replies: 5 comments 9 replies

Comment options

You must be logged in to vote
5 replies
@dabdine
Comment options

@sp88011
Comment options

@valerii15298
Comment options

@sp88011
Comment options

@valerii15298
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
2 replies
@shacthulu
Comment options

@nabilfreeman
Comment options

Answer selected by JacobWeisenburger
Comment options

You must be logged in to vote
1 reply
@brettz9
Comment options

Comment options

You must be logged in to vote
1 reply
@brettz9
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
10 participants
Converted from issue

This discussion was converted from issue #2026 on February 11, 2023 15:34.