Skip to content

Subhash1506/json-tree-visualizer

Repository files navigation

🌳 JSON Tree Visualizer

Live Demo Deploy with Vercel

An interactive web application that visualizes JSON data as a hierarchical tree structure using React Flow. Features search functionality, dark mode, and the ability to download visualizations.

🌐 Live Demo

πŸ”— Try it now!

JSON Tree Visualizer

✨ Features

Mandatory Features

  • βœ… JSON Input & Parsing: Text area for pasting JSON with validation and error messages
  • βœ… Generate Tree Button: One-click visualization of JSON structure
  • βœ… React Flow Visualization: Interactive tree with hierarchical node display
  • βœ… Color-Coded Nodes:
    • πŸ”΅ Objects: Blue/Purple gradient
    • 🟒 Arrays: Green gradient
    • 🟠 Primitives: Orange/Yellow gradient
  • βœ… Search Functionality: Search by JSON path (e.g., $.user.address.city, items[0].name)
  • βœ… Highlight & Pan: Matched nodes are highlighted and centered in view
  • βœ… Search Messages: "Match found" or "No match found" feedback

Bonus Features

  • βœ… Dark/Light Mode: Toggle between themes
  • βœ… Clear/Reset Buttons: Clear all input or reset to sample JSON
  • βœ… Copy JSON Path: Click any node to copy its path to clipboard
  • βœ… Download as Image: Export tree visualization as PNG
  • βœ… Zoom Controls: Built-in zoom in/out and fit view
  • βœ… Pan & Navigate: Drag canvas to explore large trees
  • βœ… Hover Information: View node path and value on hover
  • βœ… Sample JSON: Pre-loaded example for quick testing

πŸš€ Getting Started

Prerequisites

  • Node.js (v16 or higher)
  • npm or yarn

Installation

  1. Clone the repository
git clone <your-repo-url>
cd Tree
  1. Install dependencies
npm install
  1. Start development server
npm run dev
  1. Open in browser Navigate to http://localhost:5173

Build for Production

npm run build

The built files will be in the dist folder, ready for deployment.

πŸ“– How to Use

1. Input JSON

  • Paste or type your JSON data in the left panel
  • The app includes a sample JSON for quick testing
  • Click "Reset Sample" to restore the example

2. Visualize

  • Click the "Generate Tree" button
  • The tree will render with color-coded nodes
  • Use zoom controls and drag to navigate

3. Search

  • Enter a JSON path in the search bar:
    • $.user.name - Access nested object property
    • $.items[0].price - Access array element
    • $.address.city - Deep nested access
  • Click "Search" or press Enter
  • Matched nodes will be highlighted in red and centered

4. Interact

  • Click nodes: Copy the JSON path to clipboard
  • Hover nodes: View path and value
  • Zoom/Pan: Use controls or mouse gestures
  • Download: Export visualization as PNG image

5. Theme

  • Click the moon/sun icon to toggle dark/light mode

🎨 Node Types

Type Color Description
Object Blue/Purple JSON objects {}
Array Green JSON arrays []
Primitive Orange/Yellow Strings, numbers, booleans, null

πŸ›  Tech Stack

  • React 18: UI framework
  • Vite: Build tool and dev server
  • React Flow: Graph visualization library
  • HTML-to-Image: Download functionality
  • CSS3: Styling with gradients and animations

πŸ“‚ Project Structure

Tree/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ components/
β”‚   β”‚   β”œβ”€β”€ CustomNode.jsx       # Custom React Flow node component
β”‚   β”‚   └── CustomNode.css       # Node styling
β”‚   β”œβ”€β”€ utils/
β”‚   β”‚   └── jsonToTree.js        # JSON parsing and tree building logic
β”‚   β”œβ”€β”€ App.jsx                  # Main application component
β”‚   β”œβ”€β”€ App.css                  # Main application styles
β”‚   β”œβ”€β”€ main.jsx                 # Application entry point
β”‚   └── index.css                # Global styles
β”œβ”€β”€ index.html                   # HTML template
β”œβ”€β”€ package.json                 # Dependencies and scripts
β”œβ”€β”€ vite.config.js              # Vite configuration
└── README.md                    # Documentation

🌐 Deployment

Deploy to Netlify

npm run build
# Drag the dist folder to Netlify

Deploy to Vercel

npm run build
vercel --prod

Deploy to GitHub Pages

  1. Update vite.config.js base path to your repo name
  2. Run build and deploy:
npm run build
# Push dist folder to gh-pages branch

🎯 JSON Path Examples

// Sample JSON
{
  "user": {
    "name": "John",
    "address": {
      "city": "NYC"
    }
  },
  "items": [
    { "id": 1, "name": "Laptop" }
  ]
}

// Search paths:
$.user.name           // "John"
$.user.address.city   // "NYC"
$.items[0].name       // "Laptop"
$                     // Root object

🀝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

πŸ“ License

This project is open source and available under the MIT License.

πŸ™ Acknowledgments

πŸ“§ Contact

For questions or feedback, please open an issue on GitHub.


Made with ❀️ using React and React Flow

About

Interactive JSON Tree Visualizer with React Flow

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •