4 ms·
I don’t know. Zod feels more reasonable path forward to accomplish the same thing (granted it’s not using the language of JSON schema if you have a dependency o
by vlovich123 4y ago
I don’t know. Zod feels more reasonable path forward to accomplish the same thing (granted it’s not using the language of JSON schema if you have a dependency on that for some reason)
- girvo 4y agoZod is fantastic. Our whole front-end is built around it, with some React hooks that wrap up a `createApi` call around Zod decoders and expose them to components/containers. It's lovely. Only downside is those decoders can't be re-used across other languages, whereas technically this could be, I guess?
- evv 4y agoZod is great, but JSON-schema is my pick because it is easily serialized. So a client can query for the schema of the data it should send or receive, including descriptions/metadata that is useful for presenting a UI.
- vlovich123 4y agoZod to JSON schema is a thing so I think that solves your problem, no? https://www.npmjs.com/package/zod-to-json-schema https://www.npmjs.com/package/zod-to-json-schema
- tmerse 4y agoYou happen to know if there are libs/utils to achieve the reverse (JSON-schema -> zod)? Could be useful for one of my usecases (form validation via rules recievd as JSON)
- evv 4y agoI didn't know about this! But on the client I would use a JSON-schema validator anyways, otherwise I'd need something like "json-schema-to-zod"? Seems like a roundabout way to address my problem
- dgb23 4y agoDoes zod let me walk/parse the definitions as data?
- jitl 4y agoThe last time I tried this, I remember feeling sad and needing to wrap Zod in my own layer of stuff.
- vlovich123 4y agoI can’t recall if it’s particularly ergonomic, but technically I believe it’s possible.