Registry / web-framework / react-json-tree

react-json-tree

JSON →
library0.20.0jsnpmunverified

react-json-tree is a React component that provides an interactive JSON viewer, allowing developers to inspect JavaScript objects and arrays in a collapsible tree format. It was originally extracted from the Redux DevTools project and maintains active development within the same monorepo. The current stable version is 0.20.0, indicating a mature library. It differentiates itself by supporting iterable objects, including those from Immutable.js, and offering extensive theming capabilities through the base16 specification or custom styling functions. The component is regularly maintained, though its release cadence for major versions is tied to the broader Redux DevTools ecosystem. It's primarily used in development tools, debugging interfaces, and administrative dashboards where visual inspection of data structures is crucial.

npm install react-json-tree
INSTALL
IMPORT
SIG · REACT-JSON-TREE
R
react-json-tree
web-frameworkjavascriptv0.20.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

JSONTree
import { JSONTree } from 'react-json-tree'
const { JSONTree } = require('react-json-tree')
The primary way to import the component. CommonJS `require` for this named export can lead to `undefined` or bundling issues in modern setups.
JSONTreeProps
import type { JSONTreeProps } from 'react-json-tree'
TypeScript type definition for the `JSONTree` component's properties, useful for strong type checking.
JSONTree (default import attempt)
import { JSONTree } from 'react-json-tree'
import JSONTree from 'react-json-tree'
`JSONTree` is provided as a named export, not a default export. Attempting a default import will result in `undefined`.

This quickstart demonstrates how to render a complex JavaScript object, including Immutable.js `Map` instances, using the `JSONTree` component with a custom theme and initial expansion logic.

import { JSONTree } from 'react-json-tree'; import { Map } from 'immutable'; // Optional: if using Immutable.js import React from 'react'; import ReactDOM from 'react-dom/client'; const jsonExample = { array: [1, 2, 3], bool: true, object: { foo: 'bar', nested: { value: 42, label: 'answer' } }, immutableMap: Map({ key: 'value', another: 'item' }), nullValue: null, undefinedValue: undefined, complexArray: [{ id: 1, name: 'one' }, { id: 2, name: 'two' }] }; const App = () => ( <div> <h1>JSON Tree Viewer Example</h1> <p>Displays a complex JSON object using `react-json-tree`:</p> <div style={{ backgroundColor: '#282c34', padding: '20px', borderRadius: '8px' }}> <JSONTree data={jsonExample} theme="monokai" invertTheme={false} shouldExpandNodeInitially={(keyPath, value, depth) => depth < 2} valueRenderer={(raw) => <span style={{ color: '#61dafb' }}>{raw}</span>} /> </div> </div> ); // Assumes an HTML file with `<div id="root"></div>` const rootElement = document.getElementById('root'); if (rootElement) { const root = ReactDOM.createRoot(rootElement); root.render( <React.StrictMode> <App /> </React.StrictMode> ); } else { console.error('Root element with ID "root" not found in the document.'); }
Debug
Known issues
breakingMajor React version updates (e.g., React 19) may introduce breaking changes or require specific peer dependency ranges. Ensure your React version falls within the package's `peerDependencies` range.
fix
Upgrade `react` and `@types/react` to compatible versions. Check the package's `peerDependencies` in `package.json` for the exact supported ranges.
affects: >=0.17.0
gotchaThe `theme` prop accepts various formats: a base16 theme object, a custom styling object, or an object extending a base16 theme. Incorrectly structured theme objects, especially when using functions for advanced customization, can lead to unexpected styling or errors.
fix
Refer to the `react-json-tree` README and `createStylingFromTheme.ts` source for detailed documentation on `theme` prop structure and accepted styling keys, including the use of `extend` property for base16 themes.
affects: >=0.14.0
gotchaSome packages within the wider Redux DevTools monorepo (e.g., `@redux-devtools/extension`) have transitioned to ESM-only distribution in recent major versions. While `react-json-tree` currently supports CJS, anticipate that future major versions or ecosystem dependencies might also adopt an ESM-only approach, potentially requiring changes to import statements and build configurations.
fix
Monitor release notes for `react-json-tree` and related Redux DevTools packages. For new projects, prefer ESM import syntax (`import`) and ensure your build tooling (e.g., Webpack, Rollup) is configured to handle ESM correctly. For older CJS projects, consider using dynamic `import()` or upgrading to a modern build setup.
affects: >=0.20.0
Errors
Common errors & fixes
TypeError: (0 , react_json_tree__WEBPACK_IMPORTED_MODULE_2__.JSONTree) is not a function
Incorrect import statement in a CommonJS or mixed ESM/CJS environment, often due to bundler misconfiguration or attempting to `require` an ESM-first package.
fix
Ensure you are using `import { JSONTree } from 'react-json-tree'` for ESM. If in a CJS file, verify `require('react-json-tree').JSONTree` works, or adapt your build configuration to handle ESM imports. If an older CJS context has issues, consider using dynamic `import()` for `react-json-tree`.
Warning: Failed prop type: Invalid prop `data` of type `string` supplied to `JSONTree`, expected `object`.
The `data` prop expects an object, array, or an iterable (like `Immutable.Map`), but a primitive value (e.g., string, number, boolean) was passed directly.
fix
Ensure the `data` prop passed to `JSONTree` is a valid JavaScript object, array, or an iterable. To display primitive values, wrap them in an object, e.g., `<JSONTree data={{ value: 'hello world' }} />`.
Invariant Violation: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined.
This typically indicates that the `JSONTree` component itself, or one of its fundamental dependencies (like React), failed to load or was incorrectly imported, often due to an incompatible React version or broken build setup.
fix
Verify that `react` and `react-dom` are installed and configured correctly in your project. Check `react-json-tree`'s `peerDependencies` in `package.json` to ensure your project's React versions are compatible. Reinstall project dependencies via `npm install` or `yarn install` to resolve potential corruption.
Upgrade
Version history
0.20.0latest on npm
Audit
Dependencies
reactrequiredCore peer dependency for React component rendering.
@types/reactrequiredTypeScript type definitions for React. Required for type-safe development.
immutableoptionalOptional dependency for handling Immutable.js Map/List objects.
Agent activity
20 hits · last 30 days
node
16
OpenAI (training)
2
Amazon
1
Resources
react-json-tree — npm install react-json-tree · libregistry