Skip to content

JSON.parse source text access #1163

@MaxArt2501

Description

@MaxArt2501

Description

This proposal comprises methods and classes to access the source of JSON objects. This is necessary e.g. to correctly convert JSONs with arbitrary long numbers without losing precision, or creating JSONs without resolving to use strings or other constructs.

  • the JSON.rawJSON static method creates a "raw JSON" object containing a piece of JSON text. When serialized to JSON, the raw JSON object is treated as if it is already a piece of JSON. This text is required to be valid JSON.
  • the JSON.isRawJSON static method tests whether a value is an object returned by JSON.rawJSON()
  • third context argument for JSON.parse's reviver that holds state relevant to the current expression being revived

Currently this proposal is at stage 3 of the TC39 Process.

Specification

https://tc39.es/proposal-json-parse-with-source/

web-feature

https://web-platform-dx.github.io/web-features-explorer/features/json-raw/

Test Links

In test262: tc39/test262#3806
https://github.com/tc39/test262/tree/409001b61bd3e1546028d8b768a65ab96ac5928d/test/built-ins/JSON/rawJSON
https://github.com/tc39/test262/tree/409001b61bd3e1546028d8b768a65ab96ac5928d/test/built-ins/JSON/isRawJSON
https://github.com/tc39/test262/blob/409001b61bd3e1546028d8b768a65ab96ac5928d/test/built-ins/JSON/parse/reviver-context-source-array-literal.js
https://github.com/tc39/test262/blob/409001b61bd3e1546028d8b768a65ab96ac5928d/test/built-ins/JSON/parse/reviver-context-source-object-literal.js
https://github.com/tc39/test262/blob/409001b61bd3e1546028d8b768a65ab96ac5928d/test/built-ins/JSON/parse/reviver-context-source-primitive-literal.js

Additional Signals

Supported by Chrome since v114, Firefox v135 and Node v21. Safari only supports the context argument of JSON.parse reviver since v18.4.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions