News for hackers. Stuff that matters.
Re:BigInt Shipping in Firefox by wpq0 on Thursday May 23, 2019 @10:13AM (#19991973)
Afaict, JSON serialization is not supported yet, got a "TypeError: BigInt value can't be serialized in JSON". I'm on Firefox Developer edition 68.0b3.
Re:BigInt Shipping in Firefox by M2Ys4U on Thursday May 23, 2019 @10:34AM (#19992138)
I suppose one could use a replacer[0] when calling JSON.stringify and a reviver[1] when calling JSON.parse

[0] https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...

[1] https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...

Re:BigInt Shipping in Firefox by bpye on Thursday May 23, 2019 @11:39AM (#19992723)
You can certainly serialize to a string but knowing when you should revive to a BigInt seems tricky. You could prefix the strings I guess?
Re:BigInt Shipping in Firefox by tzs on Thursday May 23, 2019 @11:58AM (#19992897)
How about serializing to an array ["bigint", "170141183460469231731687303715884105727"]? It takes more space, but is easy to recognize, and easy to generalize to other types.
Re:BigInt Shipping in Firefox by jfk13 on Thursday May 23, 2019 @01:15PM (#19993692)
Presumably that could be confusing if you ever happen to have an actual array whose first element is the string "bigint".
Re:BigInt Shipping in Firefox by hombre_fatal on Thursday May 23, 2019 @01:43PM (#19994010)
Well, no matter what you do, surely you plan on documenting your API to such a bare bones level that your user isn't racking their brain whether a key is a number or an array of data.
Re:BigInt Shipping in Firefox by repsilat on Thursday May 23, 2019 @04:53PM (#19995802)
Nah, you just have to also encode all arrays like

    ["array", [...]]
;-)
Re:BigInt Shipping in Firefox by M2Ys4U on Thursday May 23, 2019 @05:36PM (#19996249)
True, but if you control both the serialisation and deserialisation you can get away with it
Re:BigInt Shipping in Firefox by derfniw on Thursday May 23, 2019 @12:28PM (#19993185)
Reuse the literal? (postfix with 'n')
Re:BigInt Shipping in Firefox by bufferoverflow on Thursday May 23, 2019 @01:54PM (#19994137)
You don't want strings that are "digits..n" to automatically deserialize into bigints. What if you have a string like "8n", which is a tractor model, or "9n", which is a smartphone model?

But it would be nice to have literal 8n to convert to a bigint 8n. That's not in the JSON standard though.