JSON viewer
A collapsible tree for a JSON value: an API response, a webhook payload, a settings file. Values are set apart by type, closed objects say how much they hold, and every row can copy its value or its path. For a hierarchy of your own items use the tree view it is built on.
Install
npx shadcn@latest add @thrum-pro/json-viewerThis is a Pro component. The command works once your project has a licence key: set up Pro or see pricing.
Automatically installs icons check, copy and link from the icon set.
Data shape
type JsonValue = string | number | boolean | null | readonly JsonValue[] | { readonly [key: string]: JsonValue };const value: JsonValue = {
id: "ord_1042",
items: [{ sku: "TEE-RED", qty: 2 }],
customer: { name: "Acme", "tax id": null },
};Props
| Prop | Type | Default | Description |
|---|---|---|---|
value | JsonValue | Required | The value to show: anything JSON.parse returns. |
label | string | Required | The tree's name for screen readers, such as Order response. The search field is named Search and this label. |
rootLabel | string | Default "root" | The name of the top row. |
defaultExpandDepth | number | Default 1 | Open objects and arrays down to this many levels at first. 0 shows only the top row, closed. |
toolbar | boolean | Default true | Show the search field and the Expand all and Collapse all buttons above the tree. |
search | string | – | The search text, when the parent holds it. Use it with onSearchChange. Opening the matches is up to the reader then. |
onSearchChange | (search: string) => void | – | Called with the text on every change in the search field. Each change also opens the objects that hold a match. |
maxStringLength | number | Default 80 | Strings longer than this many characters are cut, with a button that shows the rest. Enter on the row does the same. |
copyable | boolean | Default true | A copy-value and a copy-path button on every row, shown under the pointer. Ctrl+C and Ctrl+Shift+C do the same on the focused row. |
sound | boolean | Default true | Play a soft sound when an object opens or closes, and a chime when a copy lands, if the visitor has sound on. |
className | string | – | Extra classes for the frame, merged last. Give it a height, such as h-80, to scroll a long value inside it. |
childPath(), containerPaths(), searchJson() | functions | – | More exports: the path of a child, the paths of every object down to a depth, and the matches of a search with the objects to open. |
Motion and sound
Motion
- An object the reader opens fades in and slides down 4 pixels over 150 ms; its chevron turns over 150 ms.
- The copy buttons fade in over 150 ms under the pointer. A copied button shows a tick for 2 seconds.
- Reduced motion: everything changes at once.
Sound
- A soft rising tone when an object opens and a falling one when it closes.
- A chime when a value or a path is copied, and a low tone when the browser refuses the clipboard.
Sound is off until the visitor turns it on. Pass sound={false} to keep this component silent. How sound works
Accessibility
- It is a tree view: the WAI-ARIA tree pattern, one tab stop, with each row's key, a colon and its value or its size as the row's text.
- Type is not shown by colour alone: strings are in quotes, null is in italics, objects and arrays show braces or brackets and a count.
- The copy buttons stay out of the tab order so the tree is one stop; the keyboard copies with Ctrl+C. A polite line says what was copied.
- Matches are marked with the primary fill and their keys underlined; a polite line says how many there are.
- The viewer frame is a panel surface (data-surface="panel"): under a glass material it becomes translucent while keeping syntax types and search matches readable.
- Long keys and values are cut with an ellipsis on one line; a cut string shows in full and wraps when opened.
| Keys | Action |
|---|---|
| Tab | Move through the search field and the buttons, then into the tree. |
| ↓ / ↑ / Home / End | Move between rows. |
| → / ← | Open or close an object; move to its first child or its parent. |
| * | Open every object beside the focused row. |
| A to Z | Move to the next row whose key starts with the typed letters. |
| Enter | On a cut string: show all of it, or cut it again. |
| Ctrl + C / Ctrl + Shift + C | Copy the focused row's value, or its path. |
Source
The source comes with Pro
TypeScript source · Copy-paste ready · MIT-compatible for client projects · Includes all dependencies
Files and dependencies
- Adds
components/ui/json-viewer.tsx- Packages
- None
- Brings along
- Tree viewSearch fieldButtonChart foundationsSound engine
- Icons
checkcopylink
Changelog
- 1.0.0 · 2026-12-03First release.