Skip to content

JSON Viewer

Pro

Shows a JSON value as a tree that people open and close by key. They can copy a value, see its type, and see what changed.

  • React Aria
  • React 19
  • Tailwind CSS 4

Added Nov 9, 2026 · Pro license

Playground

Loading the preview

Props

Needs your Pro API key in GELATIN_UI_PRO_TOKEN. Set it up

Pro itemAPI key required

JSON Viewer needs a Pro API key

Try the live preview for free. With Pro, the add command above puts the source in your project.

Files it adds
57
More Pro items, one API key
+327
Your coding agent runs it
1 cmd

$79$129once, for life

Already have Pro? Sign in to set up your API key.

Put the viewer in a CodeBlock. Compose the header buttons and the JsonViewerContent tree. A rootName names the tree.

The sample also uses Code Block. One command adds them with this item:

api-response.tsx

JsonViewer

PropTypeDefaultDescription
palette"color""ink""theme"—
valueRequiredunknown—The value to show: JSON data, or any JS value (a Map, Set, Date, or bigint reads as JSON).
rootNamestring—Show the value itself as the first row with this name; it also names the tree.
defaultExpandDepthnumber1How many levels start open, on the first render. Default 1: the root is open, its keys are closed. Infinity opens all. The top keys are level 1 with or without rootName.
expandedPathsIterable<string>—The open rows (controlled), by path id (formatJsonPath: $.user.roles).
defaultExpandedPathsIterable<string>—The open rows at first (uncontrolled). Wins over defaultExpandDepth.
onExpandedPathsChange—
sortKeysJsonSortKeys—Sort object keys: true sorts a to z; a function sorts as Array.prototype.sort.
maxItemsnumber100The keys or items a row shows before a "Show more" row. Default 100.
groupArraysAfternumber100Split an array longer than this into closed ranges of this many items. Default 100; 0 off.
maxStringLengthnumber—Cut a string longer than this, with a button that shows the rest. Default: no cut.
typesbooleanfalseShow the type of each value at the row end (string, number, …). Default false.
countsbooleantrueShow the number of keys or items: {3} and [2], else {…}. Default true.
copybooleantrueA copy button on each row (and Cmd/Ctrl+C on the focused row). Default true.
lineNumbersbooleanfalseThe row number at the start of each shown row. Default false.
marks—Change marks by path id: a tint, and a + or − sign for inserted and deleted.
wrapboolean—Wrap long strings over lines. Default: the Wrap toggle of the Code Block, else false.
onValueSelect—Runs on Enter or a press on a row that cannot open (a value, an empty object or array), with its path and its value as JSON data. Rows that open keep opening on a press.
labelsPartial<JsonViewerLabels>—The words of the viewer (JsonViewerLabels in #/lib/pro/json-tree-model).
childrenReactNode—The parts. Default: <JsonViewerContent />.

JsonViewerContent

PropTypeDefaultDescription
aria-labelstring—Defines a string value that labels the current element.
aria-labelledbystring—Identifies the element (or elements) that labels the current element.
aria-describedbystring—Identifies the element (or elements) that describes the object.
aria-detailsstring—Identifies the element (or elements) that provide a detailed, extended description for the object.
idstring—The element's unique identifier. See MDN.
langstring—
hiddenboolean—
inertboolean—
translate"no""yes"—
suppressHydrationWarningboolean—A React-only flag that suppresses the warning React normally logs when an element's server-rendered content doesn't match the client render during hydration. See React docs.
onClickMouseEventHandler<HTMLDivElement>—
onClickCaptureMouseEventHandler<HTMLDivElement>—
onAuxClickMouseEventHandler<HTMLDivElement>—
onAuxClickCaptureMouseEventHandler<HTMLDivElement>—
onContextMenuMouseEventHandler<HTMLDivElement>—
onContextMenuCaptureMouseEventHandler<HTMLDivElement>—
onDoubleClickMouseEventHandler<HTMLDivElement>—
onDoubleClickCaptureMouseEventHandler<HTMLDivElement>—
onMouseDownMouseEventHandler<HTMLDivElement>—
onMouseDownCaptureMouseEventHandler<HTMLDivElement>—
onMouseEnterMouseEventHandler<HTMLDivElement>—
onMouseLeaveMouseEventHandler<HTMLDivElement>—
onMouseMoveMouseEventHandler<HTMLDivElement>—
onMouseMoveCaptureMouseEventHandler<HTMLDivElement>—
onMouseOutMouseEventHandler<HTMLDivElement>—
onMouseOutCaptureMouseEventHandler<HTMLDivElement>—
onMouseOverMouseEventHandler<HTMLDivElement>—
onMouseOverCaptureMouseEventHandler<HTMLDivElement>—
onMouseUpMouseEventHandler<HTMLDivElement>—
onMouseUpCaptureMouseEventHandler<HTMLDivElement>—
onTouchCancelTouchEventHandler<HTMLDivElement>—
onTouchCancelCaptureTouchEventHandler<HTMLDivElement>—
onTouchEndTouchEventHandler<HTMLDivElement>—
onTouchEndCaptureTouchEventHandler<HTMLDivElement>—
onTouchMoveTouchEventHandler<HTMLDivElement>—
onTouchMoveCaptureTouchEventHandler<HTMLDivElement>—
onTouchStartTouchEventHandler<HTMLDivElement>—
onTouchStartCaptureTouchEventHandler<HTMLDivElement>—
onPointerDownPointerEventHandler<HTMLDivElement>—
onPointerDownCapturePointerEventHandler<HTMLDivElement>—
onPointerMovePointerEventHandler<HTMLDivElement>—
onPointerMoveCapturePointerEventHandler<HTMLDivElement>—
onPointerUpPointerEventHandler<HTMLDivElement>—
onPointerUpCapturePointerEventHandler<HTMLDivElement>—
onPointerCancelPointerEventHandler<HTMLDivElement>—
onPointerCancelCapturePointerEventHandler<HTMLDivElement>—
onPointerEnterPointerEventHandler<HTMLDivElement>—
onPointerLeavePointerEventHandler<HTMLDivElement>—
onPointerOverPointerEventHandler<HTMLDivElement>—
onPointerOverCapturePointerEventHandler<HTMLDivElement>—
onPointerOutPointerEventHandler<HTMLDivElement>—
onPointerOutCapturePointerEventHandler<HTMLDivElement>—
onGotPointerCapturePointerEventHandler<HTMLDivElement>—
onGotPointerCaptureCapturePointerEventHandler<HTMLDivElement>—
onLostPointerCapturePointerEventHandler<HTMLDivElement>—
onLostPointerCaptureCapturePointerEventHandler<HTMLDivElement>—
onScrollUIEventHandler<HTMLDivElement>—
onScrollCaptureUIEventHandler<HTMLDivElement>—
onWheelWheelEventHandler<HTMLDivElement>—
onWheelCaptureWheelEventHandler<HTMLDivElement>—
onAnimationStartAnimationEventHandler<HTMLDivElement>—
onAnimationStartCaptureAnimationEventHandler<HTMLDivElement>—
onAnimationEndAnimationEventHandler<HTMLDivElement>—
onAnimationEndCaptureAnimationEventHandler<HTMLDivElement>—
onAnimationIterationAnimationEventHandler<HTMLDivElement>—
onAnimationIterationCaptureAnimationEventHandler<HTMLDivElement>—
onTransitionCancelTransitionEventHandler<HTMLDivElement>—
onTransitionCancelCaptureTransitionEventHandler<HTMLDivElement>—
onTransitionEndTransitionEventHandler<HTMLDivElement>—
onTransitionEndCaptureTransitionEventHandler<HTMLDivElement>—
onTransitionRunTransitionEventHandler<HTMLDivElement>—
onTransitionRunCaptureTransitionEventHandler<HTMLDivElement>—
onTransitionStartTransitionEventHandler<HTMLDivElement>—
onTransitionStartCaptureTransitionEventHandler<HTMLDivElement>—
selectionMode"multiple""none""single"—The type of selection that is allowed in the collection.
disallowEmptySelectionboolean—Whether the collection allows empty selection.
disabledKeysIterable<Key>—The item keys that are disabled. These items cannot be selected, focused, or otherwise interacted with.
slotstring | null—A slot name for the component. Slots allow the component to receive props from a parent component. An explicit null value indicates that the local props completely override all props received from a parent.
render—Overrides the default DOM element with a custom render function. This allows rendering existing components with built-in styles and behaviors such as router links, animation libraries, and pre-styled components. Requirements: - You must render the expected element type (e.g. if <button> is expected, you cannot render an <a>). - Only a single root DOM element can be rendered (no fragments). - You must pass through props and ref to the underlying DOM element, merging with your own prop as appropriate.
value"all" | Iterable<Key>—The picked keys (controlled).
defaultValue"all" | Iterable<Key>—The picked keys at first (uncontrolled).
onValueChange—Runs on each change, with the new picked keys and the Base UI change details.
dependenciesreadonly any[]—Values that should invalidate the item cache when using dynamic collections.
autoFocus"first""last"boolean—Whether to auto focus the gridlist or an option.
onAction—Handler that is called when a user performs an action on an item. The exact user event depends on the collection's selectionBehavior prop and the interaction modality.
shouldSelectOnPressUpboolean—Whether selection should occur on press up instead of press down.
keyboardNavigationBehavior"arrow""tab"'arrow'Whether keyboard navigation to focusable elements within grid list items is via the left/right arrow keys or the tab key.
escapeKeyBehavior"clearSelection""none"'clearSelection'Whether pressing the escape key should clear selection in the grid list or not. Most experiences should not modify this option as it eliminates a keyboard user's ability to easily clear selection. Only use if the escape key is being handled externally or should not trigger selection clearing contextually.
selectionBehavior"replace""toggle"'toggle'How multiple selection should behave in the tree.
renderEmptyState—Provides content to display when there are no items in the list.
disabledBehavior"all""selection"'all'Whether disabledKeys applies to all interactions, or only selection.
dragAndDropHooksDragAndDropHooks<NoInfer<JsonTreeRow>>—The drag and drop hooks returned by useDragAndDrop used to enable drag and drop behavior for the Tree.
classNamestring—
refRef<HTMLDivElement>—
flatboolean—A list with no parent rows: no row keeps the 20px chevron lane (and its 6px gap) empty, so the icon of each row sits at the row padding. For a flat list of the Tree look (the list view of Changed Files). A row with child rows still shows its chevron. Default false.
selectionCascadeboolean—Checks follow the folders (selectionMode="multiple"): checking a row checks every row under it, also in closed folders and at every depth; unchecking clears them; a parent is checked when all its rows are, and shows the dash when some are. Disabled rows are skipped, and a disabled folder shows the state of its rows. Rows that load or drop into a folder the user checked arrive checked, unless the user unchecked that exact row (#/lib/tree-selection-model, TreeCheckIntent). onValueChange gets the whole result, so a controlled value works. It runs on a user change, and when rows load into a checked folder; never on the mount or a render of the parent (there the Tree only draws the whole selection). Default false: React Aria's independent selection, where a folder is an item of its own.
virtualizedbooleanfalseRender only the rows in view (React Aria Virtualizer, fixed 24px rows, 44px on touch). Give the tree a height (className="h-96"). Strings do not wrap while it is on. Default false: turn it on for values with thousands of shown rows.

JsonViewerExpandAll

<button>
PropTypeDefaultDescription
classNamestring—
busyboolean—The button waits for the app (busy words): a spinner, aria-busy, and no clicks. Focus stays on the button. The style hook stays data-loading.
spinnerPlacement"center""start"—center (default): the spinner covers the label. start: it takes the leading icon slot. The icon sizes always use center, because their one icon is the label.
glass"clear""dark""light"—
rounded"default""full"—
size"default""icon""icon-lg""icon-sm""icon-xs""lg""sm""xl""xs""icon-xs"
variant"dashed""default""destructive""destructive-outline""ghost""link""media""outline""secondary""ghost"
childrenReactNode—
From Base UIButtonBase UI docs
focusableWhenDisabledbooleanfalseWhether the button should be focusable when disabled.
render—Allows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a ReactElement or a function that returns the element to render.
style—Style applied to the element, or a function that returns a style object based on the component's state.
...props<button> attributes—Every other attribute goes to the <button>, with a ref.

JsonViewerCollapseAll

<button>
PropTypeDefaultDescription
classNamestring—
busyboolean—The button waits for the app (busy words): a spinner, aria-busy, and no clicks. Focus stays on the button. The style hook stays data-loading.
spinnerPlacement"center""start"—center (default): the spinner covers the label. start: it takes the leading icon slot. The icon sizes always use center, because their one icon is the label.
glass"clear""dark""light"—
rounded"default""full"—
size"default""icon""icon-lg""icon-sm""icon-xs""lg""sm""xl""xs""icon-xs"
variant"dashed""default""destructive""destructive-outline""ghost""link""media""outline""secondary""ghost"
childrenReactNode—
From Base UIButtonBase UI docs
focusableWhenDisabledbooleanfalseWhether the button should be focusable when disabled.
render—Allows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a ReactElement or a function that returns the element to render.
style—Style applied to the element, or a function that returns a style object based on the component's state.
...props<button> attributes—Every other attribute goes to the <button>, with a ref.
  • Use it to show JSON data that people read and copy, such as an API response or a log entry.
  • Use marks to show inserted, deleted, and changed keys.
  • Use JsonViewerContent virtualized with a fixed height for thousands of rows.
  • Put it in a CodeBlock with JsonViewerExpandAll and JsonViewerCollapseAll in the header.
  • To edit the JSON text, use a Code Editor.
  • To show JSON as plain text with highlight, use a Code Block.
  • For a short list of label and value pairs, use a Data List.
Arrow DownorArrow UpMoves focus to the next or the previous row.
Arrow RightorArrow LeftOpens or closes the object or array that has focus.
HomeorEndMoves focus to the first or the last row.
Letter keysMoves focus to the next row whose key starts with the typed letters.
EnterRuns onValueSelect on a value row, or loads a Show more row.
⌘CorCtrlCCopies the value of the row that has focus, when no text is selected.

The rows are the Tree component: a React Aria treegrid with one tab stop, arrow keys, and type-ahead on the keys.

The tree is named by rootName, else "JSON", unless you give it aria-label or aria-labelledby.

An inserted or deleted mark shows a + or a − sign too, so a change does not rest on color only.

The copy button of each row has a name, and on touch each row is 44px high.

Row hover
hover · 150ms · ease-out (0, 0, 0.2, 1)

Built with

Installs with JSON Viewer

  1. AddedJSON Viewer, with Button, Code, Copy Button, Tree.
Open the release