JSON View
Render JSON objects and arrays as a collapsible tree with syntax coloring, keyboard navigation, search highlighting, and selectable text.
Default
JSON View expands levels strictly below defaultExpandDepth. Use defaultExpandDepth={1} when the first level helps users scan the object without opening every nested value.
Single line
Expanded objects with one short primitive key-value pair render on one line. Nested and long values remain multiline.
Embedded
JSON View follows surrounding text before and after expanded fields.
Wrapped
Long primitive values use the multiline layout and wrap within the available width.
Collapsed
Use defaultExpandDepth={0} when the surrounding surface needs to stay compact and users can choose which object to inspect.
Highlighted
Use makeJsonViewHighlightPattern to build the highlightPattern prop from search terms. The pattern highlights matching field names and primitive values.
Best Practices
When to use
- Use JSON View for JSON objects or arrays that users need to inspect, scan, collapse, expand, select, or copy.
- Prefer JSON View over a raw JSON string when nested structure matters or when log lines contain structured payloads.
- Use a regular code block when the value is static documentation, not an interactive product surface.
Behavior
- Start with
defaultExpandDepth={1}for log and detail surfaces where the top-level fields are useful by default. - Use
defaultExpandDepth={0}for dense tables, compact previews, or rows where expanded JSON would compete with primary row content. - Pass
highlightPatternonly for active search states. Leave itnullwhen nothing is being searched. - Keep the source data as an object or array. Do not pre-stringify JSON before passing it to
data.
Accessibility
- JSON View renders as a tree. Arrow keys move between visible nodes, Enter and Space toggle expandable nodes, and Home and End move to the first and last visible node.
- Keep the component near the text or control that introduces the JSON. The accessible tree label is
JSON, so surrounding context should identify the object. - Preserve selectable text. Users often copy JSON from logs or traces into search, support, or debugging tools.
Was this helpful?