Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement proposal-json-parse-with-source API #185

Open
nevcos opened this issue Sep 12, 2018 · 5 comments
Open

Implement proposal-json-parse-with-source API #185

nevcos opened this issue Sep 12, 2018 · 5 comments
Assignees

Comments

@nevcos
Copy link

nevcos commented Sep 12, 2018

The reviver function receives only the already converted value, which could be inconvenient if the convertion is not being done correctly by the parser.

For example, if a nunber is greater than Number.MAX_SAFE_INTEGER then the convertion will not be OK:

JSON.parse(`{"n":900719925474099123}`, function (k, v) {
  // v will be 900719925474099100 instead of 900719925474099123
  console.log(v);
})

By adding an extra string argument, will give the programmer a way to do the convertion on their own:

JSON.parse(`{"n":900719925474099123}`, function (k, v, raw) {
  return BigInt(raw);
})

Thanks

@jordanbtucker
Copy link
Member

You make a good point. I can see how this would be a useful extension to the API.

@jordanbtucker
Copy link
Member

jordanbtucker commented Oct 3, 2018

See also https://github.com/tc39/proposal-json-parse-with-source

@jordanbtucker
Copy link
Member

Thanks for the suggestions. While I like your ideas, I don't plan on adding any more features to the JSON5 parser at this time. In an effort to keep JSON5 simple, this library will be a reference parser rather than a full-featured, production-ready implementation of a JSON5 parser.

@jordanbtucker
Copy link
Member

I'm reopening this issue to track and discuss https://github.com/tc39/proposal-json-parse-with-source since it has gained some traction lately.

I will not be implementing any of the features from proposal-json-parse-with-source unless and until it gets to stage 4 of the TC39 process.

@jordanbtucker jordanbtucker reopened this May 29, 2022
@jordanbtucker jordanbtucker changed the title Add a new argument to reviver with the original string representation Implement proposal-json-parse-with-source API May 29, 2022
@jordanbtucker
Copy link
Member

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants