JSON support for BigInt in Chrome/V8

Anders Rundgren anders.rundgren.net at gmail.com
Sat Jul 28 16:26:04 UTC 2018


On 2018-07-28 18:07, Ranando King wrote:
> Don't get me wrong. I didn't suggest a means of extending JSON. I suggested a 
> means of consistently and easily reversibly serializing anything that is not
> natively handled by JSON already. 

Sure, I got that.  It would obviously work as well.
The problem is that JavaScript's BigInt is rather late in the game. The non-JavaScript platforms already have defined BigInt support, but in an *inconsistent* way.


> I think JSON is a fairly complete syntax for most purposes.

Yes, if you stick to the JavaScript core types defined some 15-20 years back.  Outside of that things are slightly less complete, at least if you include implementations as well.


> I wish it had a reference type so that recursive structures could be encoded as well, but the suggestion I've just made can even be used to encode that.

Doesn't JSON schema (disclaimer: I'm not a user), provide such things?

Anders


> On Sat, Jul 28, 2018 at 10:52 AM Anders Rundgren <anders.rundgren.net at gmail.com <mailto:anders.rundgren.net at gmail.com>> wrote:
> 
>     On 2018-07-28 16:52, Ranando King wrote:
>      > Why not just use DataURL syntax, something like this:
>      >
>      > ```js
>      > {
>      >    "field1": "data:json/bigint,12345678901234567890123456789012345678901234567890123456789012345678901234567890",
>      >    ...
>      > }
>      > ```
>      > This way, even as other objects pop up to be serialized, all that would be needed is another mime type in the format "json/<typename>". I could even see letting the "<typename>" portion hold the non-lowercased, original class name to make it even faster to deserialize such fields without knowing all possible mime types in advance. Still 100% compatible with existing JSON. Still 100% human readable/writable. Very easy to implement, and self consistent.
>      >
> 
>     I think the issue is rather: What problem do we want to solve?
> 
>     It is pretty obvious that there is no "perfect" solution.
> 
>     XML proves that there is no need for explicit type information in an information exchange format. Most sophisticated systems map keys in some way making explicit type information redundant.  That JSON do have a set of distinct data types is great, but extending that type scheme outside of the original JavaScript core, IMO only creates problems.  Nobody (in their right mind) would even think of designing a typed format where everything from a byte to BigDecimal would be represented as a single type.
> 
>     Anders
> 



More information about the es-discuss mailing list