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.aubur...@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
_______________________________________________
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to