uiwjs / react-json-view

A React component for displaying and editing javascript arrays and JSON objects.
https://uiwjs.github.io/react-json-view/
MIT License
188 stars 11 forks source link

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

Closed gregfenton closed 5 months ago

gregfenton commented 5 months ago

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:

ACTUAL:

image

gregfenton commented 5 months ago

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 commented 5 months ago

@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".

jaywcjlove commented 5 months ago

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 commented 5 months ago

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

gregfenton commented 5 months ago

PR merged

jaywcjlove commented 5 months ago

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