UI

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

order13 keys
id"ord_8Kd2Q7"
object"order"
status"fulfilled"
livemodefalse
created1757851200
currency"usd"
amount_total48600
discountnull
Loading interactive preview…

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.

CapabilityDefaultBehavior
Tree limitsBoundedUp to 100,000 chars (value), 500,000 serialized chars (data), and 64 nesting levels.
Paging50Large arrays and objects render pageSize children at a time with a "Show N more" pagination row.
SearchOnCase-insensitive key and primitive match (up to 1,000 hits), auto-expanding ancestors and pages.
Copy actionsOnRow hover/active copy value & copy path, Cmd/Ctrl+C (value), Cmd/Ctrl+Shift+C (path), footer copy.
Path footerOnDisplays 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

response3 keys
events64 items
Show 10 more54 hidden

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

response3 keys

Compact tree

Disable searchable and showPath for inline inspection with expand/collapse toolbar controls and per-row copy actions.

Tool arguments

root3 keys
status"unpaid"
quarter"Q3"
limit20

Invalid or partial JSON

Malformed or incomplete JSON displays the localized labels.invalid message without throwing.

Streaming output

Not valid JSON

Value formatting, search, and copy

JSON typeDisplay & color roleCopy value output (Cmd/Ctrl+C)
stringQuoted, stringColor (--ui-success), 1,000-char capRaw unquoted full string
numberTabular numerals, numberColor (--ui-accent)Numeric string
booleantrue / false, booleanColor (--ui-warning)"true" or "false"
nullnull, nullColor (--ui-muted)"null"
objectKey preview ({ a, b, … }) + localized key countPretty-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.

ArgumentType / defaultDescription
valuestringDefault: "{}"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.
labelstringDefault: "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.
hideLabelbooleanDefault: trueVisually hide the label (the default, as in Arc); it still names the tree.
rootNamestringDefault: "root"Name of the root value in paths, as in root.users[0].name. An identifier.
defaultExpandDepthintegerDefault: 1How many levels are open on first render: 0 closes everything, 1 opens the root. Ignored when defaultExpanded is set.
defaultExpandedstring[]—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.
searchablebooleanDefault: trueShow 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.
defaultQuerystringDefault: ""Initial search text. Later edits do not reset an existing instance; in React, query and onQueryChange control it.
pageSizeintegerDefault: 50How many children of an array or object show at first; a row at the end loads the next page.
copyablebooleanDefault: trueCopy 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.
showPathbooleanDefault: trueShow the path and type of the current row below the tree.
maxHeightintegerDefault: 420Height of the tree before it scrolls, in pixels.
labelsJsonViewerLabels—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.
recipestudio | softDefault: "studio"Visual treatment. Both recipes use the same interaction behavior.
themeJsonViewerTheme—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.
motionnone | 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.
motionOptionsJsonViewerMotionOptions—The branch open and close transition: a tween with a duration (ms) or a spring.
dirltr | 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

PropPurpose
dataParsed value normalized through JSON within the same size and depth limits as value.
expanded, onExpandedChangeControlled open branch paths and change callback (fires in both modes).
query, onQueryChangeControlled 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.
presetApplication defaults overridden by explicit instance props.
tokens--ui-* CSS variables applied after the typed theme.
ref, className, styleForwarded to the root <div> element along with native attributes.

Keyboard & accessibility

KeyContextInteraction
TabAllMoves between the search input, toolbar buttons, tree, and footer copy button.
ArrowDown, ArrowUpTreeMoves to the next or previous visible row (ArrowDown in search enters tree).
ArrowRightTreeExpands a closed branch or moves into the first child of an open branch.
ArrowLeftTreeCollapses an open branch or moves to its parent branch.
Home, EndTreeMoves to the first or last visible row.
Enter, SpaceTreeToggles a branch or loads the next page on a pagination row.
/TreeFocuses and selects the search input (typeahead is intentionally disabled).
Cmd/Ctrl+CTreeCopies the current row's value when no text is selected.
Cmd/Ctrl+Shift+CTreeCopies the current row's path when no text is selected.
Enter, Shift+EnterSearchSteps to the next or previous search match and centers it in the tree.
EscapeSearchClears 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 / keyRole
core, controlPanel surface, primary/secondary/muted ink, highlight, icon sizing.
popupRadius, borderSubtle, fontFamilyMonoPanel corners, toolbar/footer dividers, tree and path monospace.
success, warningCopy-done feedback and search match mark tints.
rowHeight (30), codeSize (13)Fixed row height and monospace font size in pixels.
stringColor, numberColor, booleanColor, nullColorPer-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": []
}

On this page