JsonViewer
Interactive JSON data viewer with expand/collapse, type indicators and copy to clipboard
Source
Package
License
Usage
JsonViewer displays JSON data as a collapsible tree. Values are serialized the same way as with JSON.stringify,
for example, Date is displayed as a string and Map as an empty object:
Default expand depth
Use defaultExpandDepth prop to set how many levels are expanded initially, the root node is always expanded:
defaultExpandDepth is applied only on mount. If value is loaded later, change the key together with the data,
or control the expanded state with expandedPaths and onExpandedPathsChange props:
Long arrays and objects
Use maxDisplayLength prop to limit the number of entries displayed in a single object or array.
The remaining entries are replaced with a "... N more items" row:
Set groupArraysAfterLength prop to split longer arrays into collapsible groups instead.
maxDisplayLength does not apply to grouped arrays:
Root name
Use rootName prop to display a label for the root node:
Expand all / collapse all controls
Set withControls prop to display expand all and collapse all buttons. Controls are hidden when allExpanded is set:
Type badges and size
Set withTypes prop to display type badges next to values and withSize prop
to display the number of items in arrays and objects:
Copy button
Set withCopy prop to display a copy button when a row is hovered or focused:
Collapse long strings
Use collapseStringsAfterLength prop to truncate long strings behind a "show more" button.
Long strings wrap onto multiple lines, target the data-wrap attribute with Styles API to change that:
Sort keys
Set sortKeys prop to sort object keys alphabetically or pass a comparator function:
Highlight items
Use highlightItems prop to highlight properties with diff colors. Keys are paths created with serializeJsonViewerPath, values are added or removed:
All expanded
Set allExpanded prop to expand all nodes and disable collapse interactions:
Line numbers
Set withLineNumbers prop to display line numbers alongside the JSON content:
Chevrons
Set withChevrons prop to display expand/collapse chevrons next to collapsible nodes:
Keyboard navigation
JsonViewer supports keyboard navigation similar to the Tree component:
↑/↓– move focus between visible nodes→– expand a collapsed node, or move focus to its first child←– collapse an expanded node, or move focus to its parentEnter/Space– toggle expand/collapse on collapsible nodes, triggeronValueSelecton primitive nodesCtrl + C/⌘ + C– copy the focused node value whenwithCopyprop is set
Accessibility
The content is rendered as an ARIA tree labelled with rootName, or JSON when it is not set.
The component is always rendered left-to-right, regardless of the application direction.