JSON support for BigInt in Chrome/V8

Rob Ede robjtede at icloud.com
Tue Jul 17 22:23:53 UTC 2018

The way I see it is that JSON is kind of a thing by itself even without JavaScript and we shouldn’t be beholden to the JS syntax of representing Bigints (123n vs 123) in JSON.

I think changing the behaviour of JSON.parse and introducing JSON5 namespace (or whatever) are both on the right track but meeting in the middle and extending the syntax of the existing JSON.parse/stringify with an options object that specified how to decode/encode bigints (string/number) would be the best approach.

For example, the Twitter API returns tweet ids as 64-bit ints. Granted they also return the is as a string for just this reason. But I don’t expect them to start including a third is field just to add an “n” onto it.

> On 17 Jul 2018, at 16:44, Cyril Auburtin <cyril.auburtin at gmail.com> wrote:
> It would be great to have
> ```js
> JSON.stringify({x: 5n, y: BigInt('6')}) === '{"x":5n,"y":6n}'
> JSON.parse('{"x": 3n}') // {x: 3n}
> ```
> I don't know how feasable it would be, maybe have a new JSON5 object if JSON can't be changed for some reasons
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20180717/85f60ca4/attachment.html>

More information about the es-discuss mailing list