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 Overflow
🌐
GitHub
github.com › alexkuz › react-json-tree
GitHub - alexkuz/react-json-tree: React JSON Viewer Component, Extracted from redux-devtools
May 14, 2020 - 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 100.0% | JavaScript 100.0%
🌐
npm
npmjs.com › package › react-json-tree
react-json-tree - npm
March 1, 2025 - 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
🌐
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.
🌐
StackBlitz
stackblitz.com › edit › react-zqnfju
React json tree viewer example - StackBlitz
A React project based on react, react-dom, react-json-view and react-json-tree-viewer
🌐
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.
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;
}
🌐
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.
Starred by 3.7K users
Forked by 500 users
Languages   JavaScript 96.4% | Shell 2.9%
🌐
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 100.0% | JavaScript 100.0%
Find elsewhere
🌐
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 › 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 100.0% | JavaScript 100.0%
🌐
UNPKG
unpkg.com › browse › react-json-tree@0.15.0 › README.md
react-json-tree/README.md
![](https://img.shields.io/npm/v/react-json-tree.svg) ### Usage ```jsx import JSONTree from 'react-json-tree' // If you're using Immutable.js: `npm i --save immutable` import { 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} /> ``` #### Result: ![](http://cl.ly/image/3f2C2k2t3D0o/screenshot 2015-08-26 at 10.24.12 AM.png) Check out [examples](examples) directory for more details.
🌐
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, json editinng) but still provides more than just rendering json with highlighting - e.g.
Starred by 235 users
Forked by 25 users
Languages   TypeScript 95.9% | CSS 4.1% | TypeScript 95.9% | CSS 4.1%
🌐
npm
npmjs.com › package › react-json-view-lite
react-json-view-lite - npm
September 6, 2025 - 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, json editinng) but still provides more than just rendering json with highlighting - e.g.
      » npm install react-json-view-lite
    
Published   Sep 06, 2025
Version   2.5.0
Author   AnyRoad
🌐
GitHub
github.com › bvaughn › react-json-tree
GitHub - bvaughn/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   bvaughn
🌐
GitHub
github.com › rsolomon › react-json-tree
GitHub - rsolomon/react-json-tree: React JSON Viewer Component, Extracted from redux-devtools
import JSONTree from 'react-json-tree' ... // 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   rsolomon
🌐
npm
npmjs.com › package › @gtk-grafana › react-json-tree
@gtk-grafana/react-json-tree - npm
December 3, 2025 - 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
🌐
React Split
uiwjs.github.io › react-json-view
react-json-view
A React component for displaying and editing javascript arrays and JSON objects.
🌐
GitHub
github.com › expreva › react-json-tree
GitHub - expreva/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 ...
Author   expreva
🌐
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
🌐
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