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
| Prop | Type | Default | Description |
|---|---|---|---|
| palette | "color""ink""theme" | — | |
| value | unknown | — | The value to show: JSON data, or any JS value (a Map, Set, Date, or bigint reads as JSON). |
| root | string | — | Show the value itself as the first row with this name; it also names the tree. |
| default | number | 1 | How 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. |
| expanded | Iterable<string> | — | The open rows (controlled), by path id (formatJsonPath: $.user.roles). |
| default | Iterable<string> | — | The open rows at first (uncontrolled). Wins over defaultExpandDepth. |
| on | — | ||
| sort | JsonSortKeys | — | Sort object keys: true sorts a to z; a function sorts as Array.prototype.sort. |
| max | number | 100 | The keys or items a row shows before a "Show more" row. Default 100. |
| group | number | 100 | Split an array longer than this into closed ranges of this many items. Default 100; 0 off. |
| max | number | — | Cut a string longer than this, with a button that shows the rest. Default: no cut. |
| types | boolean | false | Show the type of each value at the row end (string, number, …). Default false. |
| counts | boolean | true | Show the number of keys or items: {3} and [2], else {…}. Default true. |
| copy | boolean | true | A copy button on each row (and Cmd/Ctrl+C on the focused row). Default true. |
| line | boolean | false | The 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. | |
| wrap | boolean | — | Wrap long strings over lines. Default: the Wrap toggle of the Code Block, else false. |
| on | — | 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. | |
| labels | Partial<JsonViewerLabels> | — | The words of the viewer (JsonViewerLabels in #/lib/pro/json-tree-model). |
| children | ReactNode | — | The parts. Default: <JsonViewerContent />. |
JsonViewerContent
| Prop | Type | Default | Description |
|---|---|---|---|
| aria-label | string | — | Defines a string value that labels the current element. |
| aria-labelledby | string | — | Identifies the element (or elements) that labels the current element. |
| aria-describedby | string | — | Identifies the element (or elements) that describes the object. |
| aria-details | string | — | Identifies the element (or elements) that provide a detailed, extended description for the object. |
| id | string | — | The element's unique identifier. See MDN. |
| lang | string | — | |
| inert | boolean | — | |
| translate | "no""yes" | — | |
| suppress | boolean | — | 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. |
| on | MouseEventHandler<HTMLDivElement> | — | |
| on | MouseEventHandler<HTMLDivElement> | — | |
| on | MouseEventHandler<HTMLDivElement> | — | |
| on | MouseEventHandler<HTMLDivElement> | — | |
| on | MouseEventHandler<HTMLDivElement> | — | |
| on | MouseEventHandler<HTMLDivElement> | — | |
| on | MouseEventHandler<HTMLDivElement> | — | |
| on | MouseEventHandler<HTMLDivElement> | — | |
| on | MouseEventHandler<HTMLDivElement> | — | |
| on | MouseEventHandler<HTMLDivElement> | — | |
| on | MouseEventHandler<HTMLDivElement> | — | |
| on | MouseEventHandler<HTMLDivElement> | — | |
| on | MouseEventHandler<HTMLDivElement> | — | |
| on | MouseEventHandler<HTMLDivElement> | — | |
| on | MouseEventHandler<HTMLDivElement> | — | |
| on | MouseEventHandler<HTMLDivElement> | — | |
| on | MouseEventHandler<HTMLDivElement> | — | |
| on | MouseEventHandler<HTMLDivElement> | — | |
| on | MouseEventHandler<HTMLDivElement> | — | |
| on | MouseEventHandler<HTMLDivElement> | — | |
| on | TouchEventHandler<HTMLDivElement> | — | |
| on | TouchEventHandler<HTMLDivElement> | — | |
| on | TouchEventHandler<HTMLDivElement> | — | |
| on | TouchEventHandler<HTMLDivElement> | — | |
| on | TouchEventHandler<HTMLDivElement> | — | |
| on | TouchEventHandler<HTMLDivElement> | — | |
| on | TouchEventHandler<HTMLDivElement> | — | |
| on | TouchEventHandler<HTMLDivElement> | — | |
| on | PointerEventHandler<HTMLDivElement> | — | |
| on | PointerEventHandler<HTMLDivElement> | — | |
| on | PointerEventHandler<HTMLDivElement> | — | |
| on | PointerEventHandler<HTMLDivElement> | — | |
| on | PointerEventHandler<HTMLDivElement> | — | |
| on | PointerEventHandler<HTMLDivElement> | — | |
| on | PointerEventHandler<HTMLDivElement> | — | |
| on | PointerEventHandler<HTMLDivElement> | — | |
| on | PointerEventHandler<HTMLDivElement> | — | |
| on | PointerEventHandler<HTMLDivElement> | — | |
| on | PointerEventHandler<HTMLDivElement> | — | |
| on | PointerEventHandler<HTMLDivElement> | — | |
| on | PointerEventHandler<HTMLDivElement> | — | |
| on | PointerEventHandler<HTMLDivElement> | — | |
| on | PointerEventHandler<HTMLDivElement> | — | |
| on | PointerEventHandler<HTMLDivElement> | — | |
| on | PointerEventHandler<HTMLDivElement> | — | |
| on | PointerEventHandler<HTMLDivElement> | — | |
| on | UIEventHandler<HTMLDivElement> | — | |
| on | UIEventHandler<HTMLDivElement> | — | |
| on | WheelEventHandler<HTMLDivElement> | — | |
| on | WheelEventHandler<HTMLDivElement> | — | |
| on | AnimationEventHandler<HTMLDivElement> | — | |
| on | AnimationEventHandler<HTMLDivElement> | — | |
| on | AnimationEventHandler<HTMLDivElement> | — | |
| on | AnimationEventHandler<HTMLDivElement> | — | |
| on | AnimationEventHandler<HTMLDivElement> | — | |
| on | AnimationEventHandler<HTMLDivElement> | — | |
| on | TransitionEventHandler<HTMLDivElement> | — | |
| on | TransitionEventHandler<HTMLDivElement> | — | |
| on | TransitionEventHandler<HTMLDivElement> | — | |
| on | TransitionEventHandler<HTMLDivElement> | — | |
| on | TransitionEventHandler<HTMLDivElement> | — | |
| on | TransitionEventHandler<HTMLDivElement> | — | |
| on | TransitionEventHandler<HTMLDivElement> | — | |
| on | TransitionEventHandler<HTMLDivElement> | — | |
| selection | "multiple""none""single" | — | The type of selection that is allowed in the collection. |
| disallow | boolean | — | Whether the collection allows empty selection. |
| disabled | Iterable<Key> | — | The item keys that are disabled. These items cannot be selected, focused, or otherwise interacted with. |
| slot | string | 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). |
| default | "all" | Iterable<Key> | — | The picked keys at first (uncontrolled). |
| on | — | Runs on each change, with the new picked keys and the Base UI change details. | |
| dependencies | readonly any[] | — | Values that should invalidate the item cache when using dynamic collections. |
| auto | "first""last"boolean | — | Whether to auto focus the gridlist or an option. |
| on | — | 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. | |
| should | boolean | — | Whether selection should occur on press up instead of press down. |
| keyboard | "arrow""tab" | 'arrow' | Whether keyboard navigation to focusable elements within grid list items is via the left/right arrow keys or the tab key. |
| escape | "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. |
| selection | "replace""toggle" | 'toggle' | How multiple selection should behave in the tree. |
| render | — | Provides content to display when there are no items in the list. | |
| disabled | "all""selection" | 'all' | Whether disabledKeys applies to all interactions, or only selection. |
| drag | DragAndDropHooks<NoInfer<JsonTreeRow>> | — | The drag and drop hooks returned by useDragAndDrop used to enable drag and drop behavior for the Tree. |
| class | string | — | |
| ref | Ref<HTMLDivElement> | — | |
| flat | boolean | — | 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. |
| selection | boolean | — | 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. |
| virtualized | boolean | false | Render 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>| Prop | Type | Default | Description | ||||
|---|---|---|---|---|---|---|---|
| class | string | — | |||||
| busy | boolean | — | 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. | ||||
| spinner | "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" | |||||
| children | ReactNode | — | |||||
From Base UIButtonBase UI docs | |||||||
| focusable | boolean | false | Whether 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>| Prop | Type | Default | Description | ||||
|---|---|---|---|---|---|---|---|
| class | string | — | |||||
| busy | boolean | — | 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. | ||||
| spinner | "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" | |||||
| children | ReactNode | — | |||||
From Base UIButtonBase UI docs | |||||||
| focusable | boolean | false | Whether 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. | ||||
| Arrow DownorArrow Up | Moves focus to the next or the previous row. |
|---|---|
| Arrow RightorArrow Left | Opens or closes the object or array that has focus. |
| HomeorEnd | Moves focus to the first or the last row. |
| Letter keys | Moves focus to the next row whose key starts with the typed letters. |
| Enter | Runs onValueSelect on a value row, or loads a Show more row. |
| ⌘CorCtrlC | Copies the value of the row that has focus, when no text is selected. |
Built with
Installs with JSON Viewer
- Components
- Button,Code,Copy Button,Tree









