Skip to content
Thrum

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-viewer

This 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
type JsonValue = string | number | boolean | null | readonly JsonValue[] | { readonly [key: string]: JsonValue };
Sample
const value: JsonValue = {
  id: "ord_1042",
  items: [{ sku: "TEE-RED", qty: 2 }],
  customer: { name: "Acme", "tax id": null },
};

Props

PropTypeDefaultDescription
valueJsonValueRequiredThe value to show: anything JSON.parse returns.
labelstringRequiredThe tree's name for screen readers, such as Order response. The search field is named Search and this label.
rootLabelstringDefault "root"The name of the top row.
defaultExpandDepthnumberDefault 1Open objects and arrays down to this many levels at first. 0 shows only the top row, closed.
toolbarbooleanDefault trueShow the search field and the Expand all and Collapse all buttons above the tree.
searchstring–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.
maxStringLengthnumberDefault 80Strings longer than this many characters are cut, with a button that shows the rest. Enter on the row does the same.
copyablebooleanDefault trueA 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.
soundbooleanDefault truePlay a soft sound when an object opens or closes, and a chime when a copy lands, if the visitor has sound on.
classNamestring–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.
KeysAction
TabMove through the search field and the buttons, then into the tree.
↓ / ↑ / Home / EndMove between rows.
→ / ←Open or close an object; move to its first child or its parent.
*Open every object beside the focused row.
A to ZMove to the next row whose key starts with the typed letters.
EnterOn a cut string: show all of it, or cut it again.
Ctrl + C / Ctrl + Shift + CCopy the focused row's value, or its path.

Source

SourcePro

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. 1.0.0 · 2026-12-03First release.

Loading index…

Keyboard shortcuts

/Ctrl KSearch components, docs and actions
?Show this list
AAppearance studio
SSound on or off
MFull or reduced motion
TTheme: auto, light, dark
GSurface: solid or frosted
BBackdrop photograph (under glass)
CCorner radius: square to round
RReplay the demo, on a component page
DDraw new data, on a component page
←→HomeEndMove the cursor in a focused chart
EscClose a dialog, or leave a chart cursor