News for hackers. Stuff that matters.
Re:Ask HN: Do you use JSON Schema? Help us shape its future ... by throwawaymaths on Tuesday January 31, 2023 @01:12AM (#34591843)
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.
Re:Ask HN: Do you use JSON Schema? Help us shape its future ... by planede on Tuesday January 31, 2023 @04:33AM (#34593146)
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.

Re:Ask HN: Do you use JSON Schema? Help us shape its future ... by jjgreen on Tuesday January 31, 2023 @04:54AM (#34593283)
It is a scandal that JSON does not support the BigInt type.
Re:Ask HN: Do you use JSON Schema? Help us shape its future ... by throwawaymaths on Tuesday January 31, 2023 @03:11PM (#34601196)
It does. Just string encode it.
Re:Ask HN: Do you use JSON Schema? Help us shape its future ... by jjgreen on Tuesday January 31, 2023 @04:46PM (#34602707)

   1 == "1"; // true
   1n == "1"; // true
   1n == "1n"; // false
Re:Ask HN: Do you use JSON Schema? Help us shape its future ... by throwawaymaths on Tuesday January 31, 2023 @11:02PM (#34606190)
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 ... by awwright on Tuesday January 31, 2023 @10:33PM (#34605994)
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 ... by throwawaymaths on Tuesday January 31, 2023 @03:07PM (#34601130)
That is correct, but JSONschema does and there is an implicit behavioural difference introduced by the existence of the MultipleOf filter when you're dealing with floats versus integers that can't simply be elided away or excused by the lack of a distinction in the underlying type system.

The point is JSONschema could take a stand and say for example, "this filter will always fail when the operand is not the number representation of an exact integer".

Re:Ask HN: Do you use JSON Schema? Help us shape its future ... by awwright on Tuesday January 31, 2023 @10:36PM (#34606018)
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 ... by throwawaymaths on Tuesday January 31, 2023 @11:01PM (#34606183)
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.