4 ms·
Yes, it doesn't fit grammar for ordinary JSON Numbers, but since it is plain old standard JSON there is nothing wrong about it: it just puts some demand on cons
by myfonj 8y ago
Yes, it doesn't fit grammar for ordinary JSON Numbers, but since it is plain old standard JSON there is nothing wrong about it: it just puts some demand on consuming application.
Instead of
{"boring Number not greater than 2^53": 1234}
you could send something like
{"exciting huge BigInt": {"value": "12(…)89", "type": "BigInt"}}
where you have all hints what to do with it. You can even invent some funny perks, like
{"exciting huge BigInt serialized to base36":
{"value": "12(…)yz", "type": "BigInt", "base": 36}
}
assuming you could create some parseBigInt(radix) function.
- Spivak 8y agoThis seems like it unnecessarily couples the JSON representation to the language types. JSON numbers are already arbitrarily precise. How you represent the type is up to the parser. JSON.stringify(5n) === "5" JSON.parse("5") === Number(5) JSON.parse("5000000000000000000") => Error JSON.parse({ use_bignum: true }) === 5000000000000000000n A project that does something like this: https://www.npmjs.com/package/json-bignum https://www.npmjs.com/package/json-bignum