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

What’s the go-to reason to use this over ajv? In particular, being rooted in JSON Schema feels like a pretty big win tooling-wise and interop-wise.


You can reflect TS types out of it. There are 3rd party libraries to generate JSON Schemas from Zod objects, which is helpful if you have non-TS clients you want to support


Ajv has supported that for at least a couple of years afaik, and consumes JSON Schema natively which is good for consuming other APIs, not just feeding external clients—its base data format is interoperable, basically.

That’s mostly why I’m curious about the lack of mention :)


You can’t reflect types out of Ajv. TS types are compile-time, Ajv consumes JSON schemas at runtime.



That seems to show that you have to bring your own types for JSON Schema still, as evidenced by their example both explicitly defining the interface and then passing that it as an argument.

I wasn’t aware however of JSON Type Definitions, which hadn’t been invented last time I released software with Ajv, but it does appear to be able to reflect those as well as validate from them, so thank you for showing me that.


Ah, I think I misunderstood you. Yes, this does mean that you need something else to define the typescript to json schema conversion—either by using another tool or by starting from json schema and getting to the typescript types you want.

Feels like it’s worth that trade off to have a consistent experience consuming other APIs as well, but I could be wrong; I think so far I’ve only used it when I need to consume APIs rather than produce them.


Personally a big factor: I haven't had the Zod creator scrape my email and send me a newsletter asking for money. That kind of soured me on ajv.


Ohp. That sounds pretty annoying. Was this a GitHub scrape of places using the library?


I'm not 100% sure, they most likely scraped the author emails of all NPM packages that (transitively) depend on ajv. Here's the GitHub issue from back then: https://github.com/ajv-validator/ajv/issues/1202


Appreciate the pointer!


No problem!

Just to make it explicitly clear, I only received one email - reading my earlier comment back, it made it seem like there maybe was more. It could have definitely been worse!




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

Search: