JSON Viewer
Collapsible, syntax-colored JSON tree with path copying, search, and expand/collapse controls. Designed for dev dashboards, API documentation, and debugging tools.
Preview
API Response
8 keysInstallation
$ shadcn add https://ui.justinlevine.me/r/json-viewer.jsonUsage
import { JsonViewer } from "@/components/json-viewer"<JsonViewer data={myObject} title="Response" />Pass any JSON-serializable value. Click the chevron to expand/collapse nodes. Hover a row and click the path icon to copy the access path (e.g. response.metadata.preferences.theme).
Examples
Expand depth
Control how deep the tree is expanded on initial render. Set defaultExpanded to a number for depth, or true for fully expanded.
Depth 1 (default)
Depth 1
8 keysFully expanded
Fully Expanded
8 keysReal-world data
package.json
package.json
6 keysAPI list response
Search Results
3 keysType coloring
Each JSON type gets a distinct color: strings (green), numbers (blue), booleans (amber), null (muted italic), and keys (violet).
All primitive types
Type Colors
10 keysPrimitive root values
Works with non-object root values too — strings, numbers, booleans, and null render inline.
String
Number
Boolean
Null
Color themes
Pass a colorTheme prop with any shiki theme name to apply editor-style coloring. All 65 bundled shiki themes are supported. When omitted, the viewer uses your site's Tailwind theme colors.
Dracula
Dracula
8 keysNord
Nord
8 keysTokyo Night
Tokyo Night
8 keysCatppuccin Mocha
Catppuccin Mocha
8 keysOne Dark Pro
One Dark Pro
8 keysGitHub Light
GitHub Light
8 keysFeatures
- Path copying. Hover any row and click the path icon to copy the JavaScript access path (e.g.
response.teams[0].name). Handles bracket notation for non-identifier keys. - Search. Toggle the search bar to filter keys and values. Matching text is highlighted inline and non-matching branches are hidden.
- Expand / collapse all. Toolbar buttons to expand or collapse the entire tree at once.
- Copy JSON. One-click copy of the full JSON with pretty-print formatting.
API Reference
JsonViewer
Notes
- Client component. Uses
"use client"for expand/collapse state, search, and clipboard access. - No virtualization. Renders all nodes directly. Suitable for typical API payloads (up to a few hundred nodes). For very large datasets, consider truncating the data before passing it in.
- Search behavior. When a search query is active, the tree auto-expands all nodes and hides branches with no matches. Clear the search to restore the previous collapse state.
- Path format. Copied paths use JavaScript dot notation for valid identifiers and bracket notation for numeric indices or special characters (e.g.
root["special-key"]). - No dependencies. Only requires React, Tailwind, lucide-react, and the
cnutility.