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

"Uncaught TypeError: Do not know how to serialize a BigInt" #42

Closed
gregfenton opened this issue Mar 27, 2024 · 6 comments
Closed

"Uncaught TypeError: Do not know how to serialize a BigInt" #42

gregfenton opened this issue Mar 27, 2024 · 6 comments

Comments

@gregfenton
Copy link
Contributor

Using the example currently posted to the homepage:

  1. open the browser's DevTools >> Console
  2. click the "copy to clipboard" icon for the top-most node (see image)

EXPECTED:

  • data of the whole JSON object is copied to clipboard

ACTUAL:

  • exception displays in Console and nothing is copied to clipboard

image

@gregfenton
Copy link
Contributor Author

gregfenton commented Mar 27, 2024

I wonder if on this line the code should be something more like:

copyText = JSON.stringify(value, (_, v) => typeof v === 'bigint' ? v + 'n' : v, 2);

based on this SO answer.

The + 'n' would make this code consistent with the handling of a stand-alone bigint value that is done in the code here.

There does not seem to be a really good way to deal with "BigInt" in JSON, as this other answer on that same SO post outlines in great detail.

gregfenton added a commit to gregfenton/react-json-view that referenced this issue Mar 28, 2024
jaywcjlove pushed a commit that referenced this issue Mar 29, 2024
* fix: Uncaught TypeError: Do not know how to serialize a BigInt #42

* make Copied.test cases consistent
github-actions bot pushed a commit that referenced this issue Mar 29, 2024
* fix: Uncaught TypeError: Do not know how to serialize a BigInt #42

* make Copied.test cases consistent 9ce310a
jaywcjlove added a commit that referenced this issue Mar 29, 2024
@gregfenton
Copy link
Contributor Author

gregfenton commented Mar 29, 2024

@jaywcjlove did you see my recommendation on the PR conversation about creating a utility function?

I would have added it but I wasn't sure whether your team has a standard for how to add "utility functions".

github-actions bot pushed a commit that referenced this issue Mar 29, 2024
@jaywcjlove
Copy link
Member

The current team only has me actively maintaining. However, due to the large number of Git repositories I oversee, I couldn't see your PR in time. Just saw it now, and I think it's fine, so I've merged and released a new version.

@gregfenton Thx!

@gregfenton
Copy link
Contributor Author

If you want to point me to how you do utils, I'm happy to do another PR.

@gregfenton
Copy link
Contributor Author

PR merged

@jaywcjlove
Copy link
Member

@gregfenton I would be very happy to see another PR from you.

jaywcjlove pushed a commit that referenced this issue Apr 5, 2024
* fix: Uncaught TypeError: Do not know how to serialize a BigInt #42

* make Copied.test cases consistent

* refactor: add `bigIntToString()` types function
github-actions bot pushed a commit that referenced this issue Apr 5, 2024
* fix: Uncaught TypeError: Do not know how to serialize a BigInt #42

* make Copied.test cases consistent

* refactor: add `bigIntToString()` types function e5857f3
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

No branches or pull requests

2 participants