Skip to content

Ask HN: JSON API object type definitions and validation in 2023?

2 pointsselbyk1 comment
On HN

Hey HN,

We're designing a new system and have been kicking the can about JSON object definitions and validation. Soon we need to settle on a system to validate API request bodies and provide helpful error messages. We would also like to generate Typescript types.

In the past, I've used JSON Schema ( https://json-schema.org/ ) to define definitions and ajv ( https://ajv.js.org/ ) to validate, but it's a bit verbose and ajv validation errors are more cryptic than I'd like to deal with.

TypeSchema looks interesting. It seems solid (and perhaps stable?), but development hasn't been active for 2 years. It also looks like we'd still need to generate JSON Schema and choose a validation library

Anyway, I'm very curious how others are approaching this problem. How do you organize and generate validations for your type definitions? What libraries do you use to validate and provide human readable error messages?

Thank you!

Comments

There's a new spec, JSON Type Definition [1], but I don't have any experience using it.

[1] https://jsontypedef.com/

AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.