Live data from Hacker News

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

news.ycombinator.com

51–60 of 179 posts

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

#51
> 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 value of JSON Schema, etc.

0 - https://github.com/raml-org/raml-spec/blob/master/versions/r...

1 - https://swagger.io/specification/

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

#52
post #7

Soon we'll have JSLT. JSON Query, JSON Pointer, JSON signatures etc are already there. And I say that as a conscious XML user. We are going in circles. At least XML has comments.

Trying to figure out how to get from XSD to anything else in order to work with a huge dataset. Wish there was an easier way to go from XSD -> JSONSchema -> Language Model so I could go from XML straight to my language of choice (Typescript in this instance). There don’t seem to be a ton of choices from XSD -> Language either.

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

#53
post #19

Earlier quoted context omitted.

To me, saying that JSON - not JSON Schema - needs comments is like saying an array - the good old "int[3] foo = { 5, 6, 7 };" - needs comments. I'm sure there are ways to 1) use it profitably without comments and 2) add comments in non-invasive way if really needed.

Isn't that a great example of something that would benefit from comments; a generically named int array with no context? Regarding the ability to add comments to JSON, it can be done in a cumbersome manner, such as adding a field to an object called "comment", but it is a hack since this wont work for arrays anyway.

The point is that JSON is a data structure, comment is rather unnatural there. It can be added to JSON though, just like an array could be wrapped in an object with a "comment" field. Usually array name serves as a crude comment. Literate programming isn't very popular.

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

#54
post #7

Soon we'll have JSLT. JSON Query, JSON Pointer, JSON signatures etc are already there. And I say that as a conscious XML user. We are going in circles. At least XML has comments.

The jq cli tool/language is awesome already. The person who wrote it was also interestingly very competitive in Advent if Code with it too.

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

#55
post #39
post #8

Earlier quoted context omitted.

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.

> 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". Any language with a half-decent type system can represent that at the type level. And certainly any language worth knowing can trivially check whether an integer is a multiple of integer X or a string matches regexp R, which is what grandparent was gettin…

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.

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

#56
Would love an standardized ability to specify some human-readable annotation for a validation rule and then an ability to easily see this in the DETAILED or VERBOSE validation format. I.e. rather than a cryptic note that something doesn't match a `pattern: "\\S"` (best your typical library would do) I wanna say "must contain at least one non-whitespace character". And I want this standardized, so any conformant library I pick would be able to do this for me, providing a consistent experience whenever it's UI-side "on-the-fly" pre-validation or processing a submission. Unless I missed it, I think while some libraries can do this, it's not exactly standardized thing.

And maybe schema URIs weren't exactly the best idea. Not a fan how many libraries make me register a schema with some a fake URL instead of just feeding them the schema document and simply not caring where it came from at all. But since it's already there - OK, fine, it's a minor nuisance.

Otherwise, it just works.

P.S. I have no idea about the relation to OpenAPI/Swagger/RESTful APIs/whatever. I use vanilla JSON Schema as a convenient "cross-platform" DSL for JSON-serializable data structure validation, and I think it does excellent job at this. Would love to see it staying in that scope.

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

#57

This gives you a pretty good feel for where it’s at: https://json-schema.org/blog/posts/future-of-json-schema I’m invested in it. I’m using it to provide implementation-specific validation of requests to/from a third party API. I wish there was a good macOS editor or IDEA plugin for it with autocomplete etc. The static generators from examples are obscure, ugly, minimal, and can’t account for variations. It isn’t ple…

The one out of the box with IntelliJ is pretty decent for checking YAMLs with JSON Schemas, is there something you're missing?

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

#58
post #55
post #39

Earlier quoted context omitted.

> 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". Any language with a half-decent type system can represent that at the type level. And certainly any language worth knowing can trivially check whether an integer is a multiple of integer X or a string matches regexp R, which is what grandparent was gettin…

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 stage is very questionable IME.

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

#59
I considered using it some time back for API payload validations. I found it bit too verbose for my use case then. I ended up writing my own lighter version and it worked pretty well. I later open sourced it here - https://github.com/sleeksky-dev/alt-schema .

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

#60
post #6

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

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

If you want to have comments, consider using YAML for definitions where possible as it is a superset of JSON[0]:

  YAML is also a superset of JSON, so JSON files are valid in YAML.
0 - https://www.redhat.com/en/topics/automation/what-is-yaml
Post reply on HN