Closed atimmer closed 5 years ago
I implemented a toString
method on the Node
class that calls JSON.stringify
on the Node itself.
Note: If a node has a parent property this will cause a circular reference and this WILL crash your browser when using react-json-view.
It has a custom replacer that removes the parent
parameter to remove circular dependencies, so this has been fixed 🙂.
So calling JSON.parse
on this stringified tree would get you a safe JSON representation.
To be able to properly develop the tree and debug it if necessary, the tree needs to be visualized in the example.
The easiest way to implement this is to do these steps:
react-json-view
: https://www.npmjs.com/package/react-json-view. Note: If a node has aparent
property this will cause a circular reference and this WILL crash your browser when usingreact-json-view
.The other way is to, which might result in a better visualization but is a ton more work:
If you find a better visualization library that that can obviously also be used.
Parent #1903