Earlier quoted context omitted.
Ditto. It took me a while (coming from C++) to get that types are not the ideal source of truth in TypeScript, due to their disappearance at runtime. Having a runtime parser (which can consequently express things impossible with TypeScript types alone, like "a positive integer" rather than being satisfied with any instance of `number`) from which types are inferred, is a needed mindset shift made easy with Zod. I use…
Maybe I was unclear - my post was a criticism of Zod because it involves a bunch of duct tape that I'm not sure makes sense. Typebox just creates JSON Schema objects at runtime and projects them into the type system with `Static `. In so doing, you simultaneously create schema and types and the process of doing so is pleasant--you can just hand a TObject to Fastify as a validator object and you're done. Plus, with a…
Ask HN: Do you use JSON Schema? Help us shape its future stability guarantees
101–110 of 179 posts
Re: Ask HN: Do you use JSON Schema? Help us shape its future stability guarantees
#102Since we have tooling[0] that validates requests and responses at runtime, the clients can be absolutely sure of what they receive (we through 500 if the server attempts to respond with an undocumented respond) And the server is also sure about the shape of the requests. This allows us to validate everything at compile time too, generating typescript types for both client and server.
And since we have similar tooling regarding our data stores (typescript types for sql queries) most of the time if there is a bug, the code would simply not compile - pretty nifty!
Re: Ask HN: Do you use JSON Schema? Help us shape its future stability guarantees
#103Re: Ask HN: Do you use JSON Schema? Help us shape its future stability guarantees
#104Earlier quoted context omitted.
FWIW, I've had good success with Typebox over Zod for exactly this stuff. You don't need to compile out types, you just...have them.
Ditto. It took me a while (coming from C++) to get that types are not the ideal source of truth in TypeScript, due to their disappearance at runtime. Having a runtime parser (which can consequently express things impossible with TypeScript types alone, like "a positive integer" rather than being satisfied with any instance of `number`) from which types are inferred, is a needed mindset shift made easy with Zod. I use…
Re: Ask HN: Do you use JSON Schema? Help us shape its future stability guarantees
#105Earlier quoted context omitted.
We seem to talk about different things. When doing deserialization, many wouldn't expect to add a custom code which would translate data and validate it - otherwise we would write the whole deserialization ourselves, I guess.
Most validation has to be done in custom code after deserialization (e.g. maybe a schema can enforce that the "collection ID" is in the right format, but it can't enforce that that collection actually exists in the datastore). There's definitely value in having a library/code generator/etc. to mechanically do the bytes -> structured value deserialization, but the cost/benefit of doing more complex validations at that…
Re: Ask HN: Do you use JSON Schema? Help us shape its future stability guarantees
#106Earlier quoted context omitted.
The problem with XSLT wasn't that it was a fundamentally bad design, the problem was the horrible syntax. Well, and namespaces.
what was the problem? there's templates and queries and it seemed pretty clear once you read a quick intro.
XPath really started to show the warts here - it leveraged namespaces as an axis, where your XPath could utilize namespaces which were defined at a particular element in the XSLT. However, this went against generalized tooling, as you had to understand which attributes or text were paths in order to know if namespaces had semantic value beyond the XML syntax itself.
IMHO, Canonical XML and XML Infosets were an effort to ret-con the new behavior back in - that namespaces and prefixes were not just used to serialize XML arbitrarily, but were semantically important parts of the XML itself. But at this point XML was too large to evolve - even XML 1.1 had relatively little market uptake.
On top of that, you had issues with how e.g. Microsoft Internet Explorer had divergent behavior for XSLT from other browsers/the spec.
Re: Ask HN: Do you use JSON Schema? Help us shape its future stability guarantees
#107Is this the right place to complain about lack of a native Date datatype in JSON? Also lack of inheritance support. (For example I want a way to specify that my json object should be deserialized as Dog not as Animal.)
Use custom deserializers for that.
Re: Ask HN: Do you use JSON Schema? Help us shape its future stability guarantees
#108Earlier quoted context omitted.
Ditto. It took me a while (coming from C++) to get that types are not the ideal source of truth in TypeScript, due to their disappearance at runtime. Having a runtime parser (which can consequently express things impossible with TypeScript types alone, like "a positive integer" rather than being satisfied with any instance of `number`) from which types are inferred, is a needed mindset shift made easy with Zod. I use…
If you're going from Zod parsers to JSON schema, are you duplicating that in Typescript? Or can you just go ts-to-zod[1] then zod-to-json-schema? [1]: https://github.com/fabien0102/ts-to-zod
Re: Ask HN: Do you use JSON Schema? Help us shape its future stability guarantees
#109Here's my gripe with jsonschema... In most cases where I want to do some validation on JSON I find that I usually have a class/struct/object that represents the payload and I want to unpack JSON into it (or dump that class to JSON). Ultimately, there are already nice tools to do this (eg; marshmallow on the python side). So unless I'm crossing language boundaries writing a separate jsonschema and using that is more w…
Re: Ask HN: Do you use JSON Schema? Help us shape its future stability guarantees
#110> Do you use JSON Schema? At one point I did, but then discovered RAML[0] and it subsumed the value of what JSON Schema provides as well as being easier to work with than OpenAPI[1]. Also, generating JSON Schema from RAML definitions has proven to be a fairly straightforward process. The usual caveats apply... Your mileage may vary, my experiences do not speak for any others, my opinion does not detract from the valu…
What I didn't like was that it doesn't infer something is an object and instead you have "type:object" repeated a lot. Also properties rather than props.