Recursion is fun!
const data = [{
title: "Node 1",
childNodes: [
{ title: "Childnode 1.1" },
{
title: "Childnode 1.2",
childNodes: [
{
title: "Childnode 1.2.1",
childNodes: [
{ title: "Childnode 1.2.1.1" }
]
}, { title: "Childnode 1.2.2" }
]
}
]
}];
const App = () => (
<form>
<Tree data={data} />
</form>
);
const Tree = ({data}) => (
<ul>
{data && data.map(item => (
<li>
{item.title}
{item.childNodes && <Tree data={item.childNodes} />}
</li>
))}
</ul>
);
Demo: https://codesandbox.io/s/01kl2xmo40
Answer from Rick Jolly on Stack OverflowGitHub
github.com › alexkuz › react-json-tree
GitHub - alexkuz/react-json-tree: React JSON Viewer Component, Extracted from redux-devtools
Supports iterable objects, such ... // Inside a React component: const json = { array: [1, 2, 3], bool: true, object: { foo: 'bar' }, immutable: Map({ key: 'value' }) } <JSONTree data={json} /> Check out examples directory for ...
Starred by 997 users
Forked by 115 users
Languages JavaScript
npm
npmjs.com › package › react-json-tree
react-json-tree - npm
Supports iterable objects, such ... Inside a React component: const json = { array: [1, 2, 3], bool: true, object: { foo: 'bar', }, immutable: Map({ key: 'value' }), }; <JSONTree data={json} />; Check out examples directory ...
» npm install react-json-tree
Published Mar 01, 2025
Version 0.20.0
Author Shu Uesugi
Repository https://github.com/reduxjs/redux-devtools
Videos
CodeSandbox
codesandbox.io › examples › package › react-json-tree
react-json-tree examples - CodeSandbox
Use this online react-json-tree playground to view and fork react-json-tree example apps and templates on CodeSandbox.
Top answer 1 of 3
9
Recursion is fun!
const data = [{
title: "Node 1",
childNodes: [
{ title: "Childnode 1.1" },
{
title: "Childnode 1.2",
childNodes: [
{
title: "Childnode 1.2.1",
childNodes: [
{ title: "Childnode 1.2.1.1" }
]
}, { title: "Childnode 1.2.2" }
]
}
]
}];
const App = () => (
<form>
<Tree data={data} />
</form>
);
const Tree = ({data}) => (
<ul>
{data && data.map(item => (
<li>
{item.title}
{item.childNodes && <Tree data={item.childNodes} />}
</li>
))}
</ul>
);
Demo: https://codesandbox.io/s/01kl2xmo40
2 of 3
1
This example below can work on all json objects i have tested it on checkout my github repo: https://github.com/nickjohngray/blockout/blob/master/src/Tree/Tree.tsx the html generated is the same as https://www.w3schools.com/howto/howto_js_treeview.asp
class Tree extends React.Component {
processObject = (object) =>
Object.keys(object).map((key, reactKey) => {
return (
<li key={reactKey + key}>
{this.buildNode(key)}
<ul className="nested">
{this.isPrimative(object[key]) ? this.buildLeaf(object[key]) :
this.isArray(object[key]) ? this.loopArray(object[key]) : this.processObject(object[key])}
</ul>
</li>
)
})
loopArray = (array) =>
array.map((value, key) =>
<div key={key + value}>
{this.isPrimative(value) ? this.buildLeaf(value) :
this.isArray(value) ? this.loopArray(value) : this.processObject(value)}
</div>
)
isArray = (value) =>
Array.isArray(value)
isPrimative = (value) => {
return typeof (value) === 'string'
|| typeof (value) === 'number'
|| typeof (value) === 'boolean'
}
buildNode = (key: string) =>
<span className="node"
onClick={
(e) => {
this.toggle(e)
}}>
{key}
</span>
buildLeaf = (value: string) =>
<li className="leaf"
onClick={
(e) => {
}}>
{value}
</li>
toggle = (event) => {
event.target.parentElement.querySelector(".nested").classList.toggle("active");
event.target.classList.toggle("node-down");
}
render = () => <>
<ul id="myUL">
{this.processObject(json)}
</ul>
</>
}
export default Tree;
this is the css for it, copied from wc3 schools
/* Remove default bullets */
ul, #myUL {
list-style-type: none;
}
body {
background: red;
}
/* Remove margins and padding from the parent ul */
#myUL {
margin: 0;
padding: 0;
}
/* Style the caret/arrow */
.caret {
cursor: pointer;
user-select: none; /* Prevent text selection */
background: red;
}
/* Create the caret/arrow with a unicode, and style it */
.caret::before {
content: "\25B6";
color: black;
display: inline-block;
margin-right: 6px;
}
/* Rotate the caret/arrow icon when clicked on (using JavaScript) */
.caret-down::before {
transform: rotate(90deg);
}
/* Hide the nested list */
.nested {
display: none;
}
/* Show the nested list when the user clicks on the caret/arrow (with JavaScript) */
.active {
display: block;
}
CodeSandbox
codesandbox.io › examples › package › react-json-tree-view
react-json-tree-view examples - CodeSandbox
Use this online react-json-tree-view playground to view and fork react-json-tree-view example apps and templates on CodeSandbox.
GitHub
github.com › STRML › react-json-tree-editable
GitHub - STRML/react-json-tree-editable: React JSON Viewer Component, Extracted from redux-devtools
Supports iterable objects, such ... // Inside a React component: const json = { array: [1, 2, 3], bool: true, object: { foo: 'bar' }, immutable: Map({ key: 'value' }) } <JSONTree data={json} /> Check out examples directory for ...
Forked by 2 users
Languages JavaScript
GitHub
github.com › mac-s-g › react-json-view
GitHub - mac-s-g/react-json-view: JSON viewer for react · GitHub
This component provides a responsive interface for displaying arrays or JSON in a web browser. NPM offers a distribution of the source that's transpiled to ES5; so you can include this component with any web-based javascript application.
Author mac-s-g
GitHub
github.com › AnyRoad › react-json-view-lite
GitHub - AnyRoad/react-json-view-lite: Lightweight Json view component for React
react-json-view-lite is a tiny component for React allowing to render JSON as a tree. It focused on the balance between performance for large JSON inputs and functionality. It might not have all the rich features (suce as customization, copy, ...
Starred by 235 users
Forked by 25 users
Languages TypeScript 95.9% | CSS 4.1%
GitHub
github.com › Dean177 › react-native-json-tree
GitHub - Dean177/react-native-json-tree: React Native JSON Viewer Component, based on react-json-tree
Supports iterable objects, such ... // Inside a React component: const json = { array: [1, 2, 3], bool: true, object: { foo: 'bar' } immutable: Map({ key: 'value' }) } <JSONTree data={json} /> Check out the Example ...
Starred by 122 users
Forked by 33 users
Languages JavaScript
npm
npmjs.com › package › react-json-view-lite
react-json-view-lite - npm
react-json-view-lite is a tiny component for React allowing to render JSON as a tree. It focused on the balance between performance for large JSON inputs and functionality. It might not have all the rich features (suce as customization, copy, ...
» npm install react-json-view-lite
Published Sep 06, 2025
Version 2.5.0
Author AnyRoad
UNPKG
unpkg.com › browse › react-json-tree@0.15.0 › README.md
react-json-tree/README.md
 } <JSONTree data={json} /> ``` #### Result: .fill(1); const example = { avatar, string: 'Lorem ipsum dolor sit amet', integer: 42, float: 114.514, bigint: 10086n, null: null, undefined, timer: 0, date: new Date('Tue Sep 13 2022 14:07:44 GMT-0500 (Central Daylight Time)'), array: [19, 100.86, 'test', NaN, Infinity], nestedArray: [ [1, 2], [3, 4], ], object: { 'first-child': true, 'second-child': false, 'last-child': null, }, longArray, string_number: '1234', }; <JsonView value={example} />
» npm install @uiw/react-json-view
Published Jan 20, 2026
Version 2.0.0-alpha.41
Author Kenny Wang
Repository https://github.com/uiwjs/react-json-view
npm
npmjs.com › package › @gtk-grafana › react-json-tree
@gtk-grafana/react-json-tree - npm
import { JSONTree } from ... Inside a React component: const json = { array: [1, 2, 3], bool: true, object: { foo: "bar", }, immutable: Map({ key: "value" }), }; <JSONTree data={json} />;...
» npm install @gtk-grafana/react-json-tree
Published Dec 03, 2025
Version 0.0.13
Author Galen Kistler
GitHub
github.com › gaearon › react-json-tree
GitHub - gaearon/react-json-tree: React JSON Viewer Component, Extracted from redux-devtools
Supports iterable objects, such ... // Inside a React component: const json = { array: [1, 2, 3], bool: true, object: { foo: 'bar' } immutable: Map({ key: 'value' }) } <JSONTree data={ json } /> Check out examples directory for ...
Author gaearon
GitHub
github.com › STRML › react-json-tree-editable › blob › master › README.md
react-json-tree-editable/README.md at master · STRML/react-json-tree-editable
# react-json-tree · · React JSON Viewer Component, Extracted from [redux-devtools](https://github.com/gaearon/redux-devtools). Supports [iterable](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#iterable) objects, such as [Immutable.js](https://facebook.github.io/immutable-js/).
Author STRML
GitHub
github.com › okozolin › json-tree-view-material-ui
GitHub - okozolin/json-tree-view-material-ui: Show JSON api in a recursive tree view. Styles with React Material-ui
Shows it in a tree view where nodes can be expanded and collapsed. The component handles any valid JSON, without any expectations regarding its structure. TThe page that contains the component controls the URL from which the data is obtained. The URL is assumed to be publicly available without authentication. Changing the URL should fetch the data and updateaccordingly. This project was bootstrapped with Create React App.
Author okozolin
npm
npmjs.com › package › react-native-json-tree
react-native-json-tree - npm
Supports iterable objects, such ... // Inside a React component: const json = { array: [1, 2, 3], bool: true, object: { foo: 'bar' } immutable: Map({ key: 'value' }) } <JSONTree data={json} /> Check out the Example ...
» npm install react-native-json-tree
Published Feb 04, 2025
Version 1.5.0
Author Dean Merchant
React Split
uiwjs.github.io › react-json-view
react-json-view
A React component for displaying and editing javascript arrays and JSON objects.
Npm
npm.io › package › react-json-tree
React-json-tree NPM | npm.io
Supports iterable objects, such ... Map } from 'immutable'; // Inside a React component: const json = { array: [1, 2, 3], bool: true, object: { foo: 'bar', }, immutable: Map({ key: 'value' }), }; <JSONTree data={json} />; Check out examples directory for more detail...