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

feat: custom JSON serializer support #324

Merged
merged 1 commit into from
Mar 17, 2022

Conversation

mkazlauskas
Copy link
Contributor

Context

If you need to support numeric values larger than Number.MAX_SAFE_INTEGER, you can't use built-in JSON.parse/JSON.stringify.

While most JSON parsers assume numeric values have same precision restrictions as IEEE 754 double, JSON specification does not say anything about number precision. Any floating point number in decimal (optionally scientific) notation is valid JSON value. It's a good idea to serialize values which might fall out of IEEE 754 integer precision as strings in your JSON api, but { "value" : 9223372036854775807}, for example, is still a valid RFC4627 JSON string, and in most JS runtimes the result of JSON.parse is this object: { value: 9223372036854776000 }

source

Proposed solution

Add a new optional option: jsonSerializer

Copy link
Member

@jasonkuhrt jasonkuhrt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you write docs for this (readme):

  • reference, this exists, how to use it
  • guide, when you'd use it, how, why

@mkazlauskas
Copy link
Contributor Author

Added a section in README examples. Let me know if any additional docs are needed.

Copy link
Member

@jasonkuhrt jasonkuhrt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@jasonkuhrt jasonkuhrt merged commit b01d753 into graffle-js:master Mar 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants