JSON
Inspect structured JSON in a collapsible tree with live search, paging for large arrays, and one-click value or path copy.
import { JsonViewer } from '@uthereal/ui/json-viewer'Json viewer playground
JSON
Overview
JsonViewer renders structured JSON—API responses, tool outputs, or stored records—as a collapsible WAI-ARIA tree. Values are colored and announced by type, live search highlights matches and expands ancestor branches, large arrays and objects load in pages, each row copies its value or JavaScript path, and a footer displays the current path.
Use JsonViewer for interactive JSON inspection. Use Code for formatted source text and Sidebar for general hierarchical navigation.
| Capability | Default | Behavior |
|---|---|---|
| Tree limits | Bounded | Up to 100,000 chars (value), 500,000 serialized chars (data), and 64 nesting levels. |
| Paging | 50 | Large arrays and objects render pageSize children at a time with a "Show N more" pagination row. |
| Search | On | Case-insensitive key and primitive match (up to 1,000 hits), auto-expanding ancestors and pages. |
| Copy actions | On | Row hover/active copy value & copy path, Cmd/Ctrl+C (value), Cmd/Ctrl+Shift+C (path), footer copy. |
| Path footer | On | Displays the active node's JS path (root.users[0].name), type/count summary, and focusable copy. |
Usage
'use client'
import { JsonViewer } from '@uthereal/ui/json-viewer'
export function ResponseBody({ body }: { body: string }) {
return <JsonViewer label="Response body" value={body} />
}Pass serialized JSON text in value, or pass parsed JavaScript values in React via data (normalized through JSON.stringify). Unparseable text, cyclic or BigInt data, and payloads exceeding the size or depth limits display a status message instead of the tree.
<JsonViewer label="Order" data={order} defaultExpandDepth={2} />Examples
Paging large arrays
Arrays and objects with more entries than pageSize render a pagination row showing how many children remain hidden. Set rootName to customize the path prefix.
Delivery events
Live search
defaultQuery opens the tree on an active search, highlighting matching keys and primitive values, opening ancestor branches, and centering the first match in the scroll container.
Delivery events
Compact tree
Disable searchable and showPath for inline inspection with expand/collapse toolbar controls and per-row copy actions.
Tool arguments
Invalid or partial JSON
Malformed or incomplete JSON displays the localized labels.invalid message without throwing.
Streaming output
Value formatting, search, and copy
| JSON type | Display & color role | Copy value output (Cmd/Ctrl+C) |
|---|---|---|
string | Quoted, stringColor (--ui-success), 1,000-char cap | Raw unquoted full string |
number | Tabular numerals, numberColor (--ui-accent) | Numeric string |
boolean | true / false, booleanColor (--ui-warning) | "true" or "false" |
null | null, nullColor (--ui-muted) | "null" |
object | Key preview ({ a, b, … }) + localized key count | Pretty-printed 2-space indented JSON |
array | […] preview + localized item count ([] when empty) | Pretty-printed 2-space indented JSON |
Controlled search uses query and onQueryChange; controlled branch expansion uses expanded and onExpandedChange (which excludes temporary search-opened branches). Expand all opens branches breadth-first up to ~1,000 visible rows; Collapse all resets pages and keeps only the root branch open.
API reference
Serializable arguments and defaults come directly from jsonViewerConfigSchema.
| Argument | Type / default | Description |
|---|---|---|
value | stringDefault: "{}" | The JSON text to show, up to 100,000 characters and 64 nesting levels. Text that does not parse shows the invalid message instead of the tree. In React, `data` passes parsed data instead. |
label | stringDefault: "JSON" | Name of the tree, e.g. "Response body". It names the tree for assistive technology; shown above the toolbar only when hideLabel is false. |
hideLabel | booleanDefault: true | Visually hide the label (the default, as in Arc); it still names the tree. |
rootName | stringDefault: "root" | Name of the root value in paths, as in root.users[0].name. An identifier. |
defaultExpandDepth | integerDefault: 1 | How many levels are open on first render: 0 closes everything, 1 opens the root. Ignored when defaultExpanded is set. |
defaultExpanded | string[]— | Paths of the branches open on first render, e.g. ["root", "root.users"]. Later edits do not reset an existing instance; in a composition the stored state wins. |
searchable | booleanDefault: true | Show the search pill. Matching keys and values are highlighted, the branches holding them open, a counter with previous and next steps appears inside it, Enter steps through the matches and Escape clears it. `/` in the tree jumps to it. |
defaultQuery | stringDefault: "" | Initial search text. Later edits do not reset an existing instance; in React, query and onQueryChange control it. |
pageSize | integerDefault: 50 | How many children of an array or object show at first; a row at the end loads the next page. |
copyable | booleanDefault: true | Copy actions at the end of the hovered and current row (its value, strings as they are and arrays and objects as indented JSON, and its path), Ctrl or Cmd+C on the current row (Shift copies the path), and a path copy button in the footer. |
showPath | booleanDefault: true | Show the path and type of the current row below the tree. |
maxHeight | integerDefault: 420 | Height of the tree before it scrolls, in pixels. |
labels | JsonViewerLabels— | Every visible and announced text: search, match counter and steps, expand and collapse all, copy buttons and results, page rows, sizes ({count} item or items, key or keys, chosen by the locale plural rules), messages and type names. |
recipe | studio | softDefault: "studio" | Visual treatment. Both recipes use the same interaction behavior. |
theme | JsonViewerTheme— | Color mode, accent, and tokens for colors and type, popupRadius for the panel, borderSubtle for its dividers, fontFamilyMono, rowHeight, codeSize and the value colors (stringColor, numberColor and booleanColor default to the success, accent and warning roles as in Arc; nullColor). See Theming. |
motion | none | subtle | expressiveDefault: "subtle" | Animation preset: branches open and close, the current-row highlight glides between rows, the match counter slides in and copy glyphs swap. System reduced-motion preferences take precedence. |
motionOptions | JsonViewerMotionOptions— | The branch open and close transition: a tween with a duration (ms) or a spring. |
dir | ltr | rtl— | Reading direction; indentation and the arrow keys that open and close branches follow it. Paths and values stay left to right. Omit it to inherit the page direction. |
JsonViewerLabels overrides any visible or announced text. {count}, {current}, and {total} format with the active locale's number and plural rules.
React integration
| Prop | Purpose |
|---|---|
data | Parsed value normalized through JSON within the same size and depth limits as value. |
expanded, onExpandedChange | Controlled open branch paths and change callback (fires in both modes). |
query, onQueryChange | Controlled search query and change callback (fires in both modes). |
onSelect(path, value) | Fires whenever the current row changes, starting with the root. |
onCopyResult(copied, detail) | Reports clipboard success/failure with { kind: 'value' | 'path', path }. |
renderIcon(name, context) | Replaces decorative icons for indicator, toolbar, copy, or message slots. |
preset | Application defaults overridden by explicit instance props. |
tokens | --ui-* CSS variables applied after the typed theme. |
ref, className, style | Forwarded to the root <div> element along with native attributes. |
Keyboard & accessibility
| Key | Context | Interaction |
|---|---|---|
Tab | All | Moves between the search input, toolbar buttons, tree, and footer copy button. |
ArrowDown, ArrowUp | Tree | Moves to the next or previous visible row (ArrowDown in search enters tree). |
ArrowRight | Tree | Expands a closed branch or moves into the first child of an open branch. |
ArrowLeft | Tree | Collapses an open branch or moves to its parent branch. |
Home, End | Tree | Moves to the first or last visible row. |
Enter, Space | Tree | Toggles a branch or loads the next page on a pagination row. |
/ | Tree | Focuses and selects the search input (typeahead is intentionally disabled). |
Cmd/Ctrl+C | Tree | Copies the current row's value when no text is selected. |
Cmd/Ctrl+Shift+C | Tree | Copies the current row's path when no text is selected. |
Enter, Shift+Enter | Search | Steps to the next or previous search match and centers it in the tree. |
Escape | Search | Clears the search query and folds temporary search-opened branches. |
The tree implements the WAI-ARIA treeview pattern (role="tree" named by label, role="treeitem" with aria-level, aria-posinset, aria-setsize, aria-expanded, aria-selected, and child role="group"). Pre-mounted role="status" live regions announce match counts and copy outcomes. In right-to-left (dir="rtl") layouts, indentation, arrow navigation, and action-fade gradients mirror while paths and primitive values stay left-to-right. On narrow viewports (<= 420px), indentation tightens to 12px, keys cap at 40%, and the footer type summary hides. Under forced-colors: active, search inputs, match marks, active rows, and focus outlines map to system Highlight / ButtonText colors.
Motion and theming
Rows unfold their height on the smooth spring and fade in over 160ms; above 400 visible rows, per-row unfold disables automatically so bulk updates stay instant. The active-row highlight glides on the smooth spring (layoutId, snapping immediately when an active descendant folds away), tree scrolling springs smoothly to keep the current row in view, the match counter slides in, and copy buttons swap glyphs through a brief blur. Under prefers-reduced-motion: reduce, row unfolds and scroll jumps are immediate while search counters and copy icons use a 120ms opacity-only crossfade and button press scale disables. Under motion="none", every animation and transition is immediate (0ms).
| Token group / key | Role |
|---|---|
core, control | Panel surface, primary/secondary/muted ink, highlight, icon sizing. |
popupRadius, borderSubtle, fontFamilyMono | Panel corners, toolbar/footer dividers, tree and path monospace. |
success, warning | Copy-done feedback and search match mark tints. |
rowHeight (30), codeSize (13) | Fixed row height and monospace font size in pixels. |
stringColor, numberColor, booleanColor, nullColor | Per-type value colors (default to success, accent, warning, muted). |
UtherealProvider supplies application-wide defaults. See Motion.
Composition
In agent compositions, JsonViewer is a leaf component. Open branch paths persist in host state at /components/instance-<id>/expanded and reconcile against valid branches of value.
{
"type": "JsonViewer",
"props": {
"label": "Response body",
"value": "{\"invoice\":{\"number\":\"INV-1042\",\"paid\":false}}",
"defaultExpandDepth": 2
},
"children": []
}