Slight return to BigInt. Was: JSON.parse should be simple and idiot-proof
anders.rundgren.net at gmail.com
Sun Oct 21 07:18:04 UTC 2018
On 2018-10-21 08:01, kai zhu wrote:
> wish to express skepticism for the stage-1 proposal "JSON.parse source text access" , from web-integration perspective.
Be happy, now you have not less than TWO proposals for extending the ES6 JSON object! :-)
A [potentially biased] comparison between https://github.com/gibson042/ecma262-proposal-JSON-parse-with-source and https://github.com/cyberphone/es6-bigint-json-support#21-the-jsonnumber-primitive:
The introduction of a JSONNumber type in the latter proposal:
- only requires an optional extra boolean flag to JSON.parse()
- also works in the other direction, JSON.stringify(). Without changing the API
- is compatible both with "stream parsing" using the reviver function as well as the more commonly used "see what you got after parsing" method
- addresses the only real short-coming of the ES6 JSON object, namely JSON number handling
It is also worth keeping in mind that the JSON world is slowly drifting towards "schemas" making the ES6 JSON object less interesting.
Although I indeed wrote a specification for dealing with with JSON numbers outside of IEEE double precision, I still claim that the advantages of using the RFC mode is ZERO, and in fact introduces new problems like forcing stream/schema parsing or introducing "super types" like my JSONNumber. "Fulfilling RFCs" is not something application programmers are particularly concerned with.
Expressing "big":5656565656565656565 as "big":"5656565656565656565" is simply put not a big deal. The way this is currently implemented in for example JDK is anyway incompatible with just about everything else out there :-)
> standard-operating-procedure for reviving JSON-data is a 2-step process:
> 1. JSON.parse with zero-config to rule-out bugs during this step
> 2. second-pass of plain-JSON to revive [product-specific] string-encoded non-JSON datatypes like BigInt/Date/RegExp, where bugs can be expected
> you normally do not want to complicate bug-hunts by contaminating step-1 with bugs from step-2.
>  stage-1 proposal - JSON.parse source text access
> kai zhu
> kaizhu256 at gmail.com <mailto:kaizhu256 at gmail.com>
> es-discuss mailing list
> es-discuss at mozilla.org
More information about the es-discuss