react-json-tree
React JSON Viewer Component, Extracted from redux-devtools. Supports iterable objects, such as Immutable.js.
Usage
Result:
Check out examples directory for more details.
Theming
This component now uses react-base16-styling module, which allows to customize component via theme
property, which can be the following:
base16 theme data. The example theme data can be found here.
object that contains style objects, strings (that treated as classnames) or functions. A function is used to extend its first argument
{ style, className }
and should return an object with the same structure. Other arguments depend on particular context (and should be described here). See createStylingFromTheme.js for the list of styling object keys. Also, this object can extendbase16
theme viaextend
property.
Every theme has a light version, which is enabled with invertTheme
prop.
Result (Monokai theme, dark background):
Advanced Customization
Customize Labels for Arrays, Objects, and Iterables
You can pass getItemString
to customize the way arrays, objects, and iterable nodes are displayed (optional).
By default, it'll be:
But if you pass the following:
Then the preview of child elements now look like this:
Customize Rendering
You can pass the following properties to customize rendered labels and values:
In this example the label and value will be rendered with <strong>
and <em>
wrappers respectively.
For labelRenderer
, you can provide a full path - see this PR.
More Options
shouldExpandNode: function(keyName, data, level)
- determines if node should be expanded (root is expanded by default)hideRoot: Boolean
- iftrue
, the root node is hidden.sortObjectKeys: Boolean | function(a, b)
- sorts object keys with compare function (optional). Isn't applied to iterable maps likeImmutable.Map
.
Credits
All credits to Dave Vedder (veddermatic@gmail.com), who wrote the original code as JSONViewer.
Extracted from redux-devtools, which contained ES6 + inline style port of JSONViewer by Daniele Zannotti (dzannotti@me.com)
Iterable support thanks to Daniel K.
npm package created by Shu Uesugi (shu@chibicode.com) per this issue.
Similar Libraries
License
MIT
Last updated