Hacker News new | past | comments | ask | show | jobs | submit login

This would require changing the JSON spec (good luck) as it doesn't fit the grammar for JSON numbers.



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.


This 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




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: