Live data from Hacker News

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

news.ycombinator.com

161–170 of 179 posts

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

#161
post #87
post #4

just commentary on JSON Scheme itself: I mainly seem to have no leapfrogged the need for this There was a time when the JSON parsers across different platforms were so finicky that schemas seemed like a solution, but the parsers got better at not breaking on unexpected data types or JSON structures I'm also usually able to do system design to return a smaller subset of data, with consistent data types Or someone else…

Validating JSON parsers is not really what JSON schema solves.

we agree on that, one of the examples of using JSON schema is regarding the range of values of a key

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

#162

Earlier quoted context omitted.

Neither binary nor decimal floating point types exist in the JSON spec. The JSON spec does not give an explicit internal representation for floating points, implementations are free to use decimal types internally, if they wish to do so. The JSON spec merely specifies what a "number" is at the grammar level. Having said that most implementations don't use decimal floating points to represent these.

It is a scandal that JSON does not support the BigInt type.

It does. In fact, not only does JSON support big ints, but it supports arbitrary-precision base-10 decimal numbers.

Whether your JSON parser will preserve the precision correctly is another story. For JavaScript/ECMAScript, you'll need to use a library.

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

#163

Earlier quoted context omitted.

That sounds like a limitation of the implementation. Decimal types exist. If the implementation wants to account for some floating point errors I think that's fine too. If they want to codify it though, maybe add an epsilon param so the user can specify how close they want it to be.

Decimal types don't exist in JSON. If you need decimals, you definitely should encode them as strings. As JSONschema exists to document JSON, it should be agnostic to that. You can if you wish, provide format information in the format field, which is not prescriptive.

This is wrong. All numbers in JSON are arbitrary-precision base-10 decimal numbers.

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

#164

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.

The behavior is perfectly well defined... there's no special cases for integers vs. rational numbers, they're all the same.

For example, given multipleOf: 0.3, and an input of 0.9, 0.9/0.3 is 3, which is an integer, so would be accepted. A value of 0.8 would be rejected.

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

#165

Earlier quoted context omitted.

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)

I think what you're getting hung up on is that JSON does not use IEEE floating point math. If your implementation or environment stores parsed numbers as an IEEE floating point, that's a limitation the implementation has to disclose or work around in some fashion, but it's not a limitation of JSON or JSON Schema as such.

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

#166

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.

The behavior is perfectly well defined... there's no special cases for integers vs. rational numbers, they're all the same. For example, given multipleOf: 0.3, and an input of 0.9, 0.9/0.3 is 3, which is an integer, so would be accepted. A value of 0.8 would be rejected.

0.3 is not the same thing as 3/10 in ieee754, neither is 0.1 the same as 1/10.

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

#167

Earlier quoted context omitted.

Decimal types don't exist in JSON. If you need decimals, you definitely should encode them as strings. As JSONschema exists to document JSON, it should be agnostic to that. You can if you wish, provide format information in the format field, which is not prescriptive.

This is wrong. All numbers in JSON are arbitrary-precision base-10 decimal numbers.

No they aren't. The JSON spec says implementation is up to the engine and de facto JSON numbers are parsed as ieee754 on just about every platform I can think of.

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

#168

Earlier quoted context omitted.

It does. Just string encode it.

1 == "1"; // true 1n == "1"; // true 1n == "1n"; // false

You have to describe what your encoding is in the "format" field of your JSONschema and implement the correct semantic meaning.

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

#170
post #146

Earlier quoted context omitted.

Watch out for that second link. Not everything there is accurate. If you or anyone has suggestions to improve the docs (first link), filing issues or PRs are more than welcome!

> Watch out for that second link. Not everything there is accurate. Can you elaborate please? I particularly like their well formedness concept.

Part of the problem is they wrote that site and its content for a specific version of JSON Schema. The `items` keyword no longer takes an array form value in the latest version of the specification, while their documentation shows that it does.

I seem to recall other issues, but can't find them now. We may have raised issues which were resolved, but I don't recall the specifics.

Post reply on HN