Live data from Hacker News

Ask HN: Do you use JSON Schema? Help us shape its future stability guarantees

news.ycombinator.com

71–80 of 179 posts

Re: Ask HN: Do you use JSON Schema? Help us shape its future stability guarantees

#71

I haven't used JSON Schema (knowingly, at least) in my professional software career. I wonder why that is. There are things that seem to supersede it, namely type systems. GraphQL types with compiled clients wouldn't have a need for this (I don't think?). Neither would Golang generated clients from GraphQL specs, nor gRPC/protobufs. JSON storage / data passing within applications is covered by Typescript. For librari…

Used by:

- OpenAPI/Swagger (1), which is the industry standard for REST API. Used by Kubernetes among others for resource descriptions - OpenRPC (json-rpc standard) - Most YAML based configuration files.

GraphQL doesn't quite supersede JSONSchema because it doesn't deal with validation. (Something like Cue (https://cuelang.org/) might)

Type systems are not typically cross-language, which is where JSONSchema tends to be used a lot.

There are indeed a lot of openapi-based client generators. This one, for example, has been around for quite some time: https://github.com/OpenAPITools/openapi-generator

(1) Kinda. OpenAPI schema and JSONSchema are largely intersecting sets but there are bits in both that aren't present in the other.

Re: Ask HN: Do you use JSON Schema? Help us shape its future stability guarantees

#72

I use JSONschema, it's honestly great the way it is [0]. So I guess the guarantee I want is "don't change anything"? Ha. [0] my biggest gripe is it's not well defined what to do with multipleOf when the number isn't an exact integer.

Your [0] might be a change that can be made in a backwards compatible manner.. as long as current implementations don't diverge on what they do when the number is not an integer (whether they error or do something)

I think you would have to build in a "integerMultipleOf" filter and slow-deprecate "multipleOf"

To be more specific, since I wasn't in GP... It's not clear what you should do when for example you want to see if 0.3f is a "multiple of" 0.1f (due to the whole 0.30000000000004 thing)

Re: Ask HN: Do you use JSON Schema? Help us shape its future stability guarantees

#74

I haven't used JSON Schema (knowingly, at least) in my professional software career. I wonder why that is. There are things that seem to supersede it, namely type systems. GraphQL types with compiled clients wouldn't have a need for this (I don't think?). Neither would Golang generated clients from GraphQL specs, nor gRPC/protobufs. JSON storage / data passing within applications is covered by Typescript. For librari…

I had a similar experience evaluating the state of the ecosystem and finding it not ideal. The schema format is great and schemas are great ways to validate your input / make your programs easier to reason about — but with the state of the ecosystem, it’s hard to actually make use of that validation in any but the most trivial ways.

The problem with using it directly was that the validators did not produce very usable output. At one point I found myself using it to validate big tables of AirTable-hosted data that were sent into a system as JSON blobs. Identifying the error in a field, and displaying that error to a user so they could correct it, was quite possible, but was a hack in reverse engineering a specific validator system and parsing and mapping its descriptions about where the error was. This was at its worst when you had to have a subschema that was oneOf a few different things: communicating back what was wrong was incredibly painful, as there was basically no metadata coming back that could point you at the problem, just “this object has to be one of a few things, but wasn’t.” In my case I was able to add a second pass of validation if that error came back, validating a specific subschema depending on what type of thingy had been submitted exactly, then mapping that back to the original input fields, before translating those into hyperlinks where the operator could take action.

It was further compounded by a library that referenced any shared sub-schemas by loading the URI. I had to write my own system to load them up at application boot instead, and lock down the load-over-network capability for sanity’s and safety’s sake.

I didn’t see things that were much better when I attempted to work with it in Ruby, either.

The best way to use JSON Schema in a Python API project, in the end, seemed to be to use FastAPI to output the OpenAPI schema and check that in as an artifact (and test it being up to date in the unit tests) so that diffs in the API were obvious at code review.

Re: Ask HN: Do you use JSON Schema? Help us shape its future stability guarantees

#75

Here'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…

Here's my gripe with random HN comments: this has nothing to do with stability guarantees of the specification or not, unless I'm missing something in your comment. You basically just saw "JSON Schema" and thought "Aha, JSON Schema, here is why I don't like it at all, regardless of why you started this conversation"

[deleted]

Re: Ask HN: Do you use JSON Schema? Help us shape its future stability guarantees

#76

I haven't used JSON Schema (knowingly, at least) in my professional software career. I wonder why that is. There are things that seem to supersede it, namely type systems. GraphQL types with compiled clients wouldn't have a need for this (I don't think?). Neither would Golang generated clients from GraphQL specs, nor gRPC/protobufs. JSON storage / data passing within applications is covered by Typescript. For librari…

glTF is a 3D model format. It's a JSON file with optional binary data. JSON Schema is used to define the JSON part. The properties reference in the spec is autogenerated from the schemas: https://registry.khronos.org/glTF/specs/2.0/glTF-2.0.html#pr...

Re: Ask HN: Do you use JSON Schema? Help us shape its future stability guarantees

#77
post #6

It really needs comments. Unfortunately it'll never be backwards compatible. It's very helpful for debugging

It already has comments[1]?

[1]: https://json-schema.org/understanding-json-schema/reference/...

Re: Ask HN: Do you use JSON Schema? Help us shape its future stability guarantees

#78
post #8

Here'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…

Wonder in which language class members can have such JSON Schema requirements as "an integer which is a multiple of integer X" or "string which matches regexp R". Also not sure which other schema system is better than JSON Schema across many different features.

This will be possible in my programming language https://letlang.dev It's going all in on dynamic typing.

NB: It's actually already possible, since the type system is already implemented, it's just that many features of the language are not yet available.

Re: Ask HN: Do you use JSON Schema? Help us shape its future stability guarantees

#79
post #36

JSON Schema is awesome. I wish Typescript had better support for it though, having to do stuff in Zod and JSON Scheme sucks. I have a system I built that compiles TS types to JSON schema, which then validates data coming into my endpoints, this way I am typesafe at compile time (Typescript API) but if someone hits my REST endpoint w/o using my library, I still get runtime goodness. The number of different ways that J…

What tool do you use to generate json schema from typescript?

Re: Ask HN: Do you use JSON Schema? Help us shape its future stability guarantees

#80

I haven't used JSON Schema (knowingly, at least) in my professional software career. I wonder why that is. There are things that seem to supersede it, namely type systems. GraphQL types with compiled clients wouldn't have a need for this (I don't think?). Neither would Golang generated clients from GraphQL specs, nor gRPC/protobufs. JSON storage / data passing within applications is covered by Typescript. For librari…

Aside from your passing mention of Go, it sounds like your working life is almost exclusively in Typescript. "A client library with Typescript types" is not a substitute for a schema that can be used in multiple languages.

(I have the opposite working life to you: I use lots of languages but none are based on JS. So I don't feel qualified to say this, but I don't see how a mish mash of hand written client libraries is a substitute even if you do only work in Typescript. What if I write my own JSON data at the application level? Do I have to write my own mini Typescript library to encode and decode it? It's going to be less concise than specifying the format in a schema.)

Post reply on HN