jsonPreview Renderer
renderAs: 'jsonPreview' renders an object or array as an interactive collapsible JSON tree. String values that parse as JSON are automatically expanded.
Core Examples
Expanded by Default
Nested metadata object displayed as an expandable JSON tree.
{ key: 'meta', renderAs: 'jsonPreview', renderAsOptions: { defaultCollapsed: false } }
Collapsed with Depth Limit
defaultCollapsed: true folds nested nodes on initial render. The root object always stays expanded — only children at depth > 0 are collapsed. maxDepth truncates structures deeper than the given level.
Same metadata with nested nodes collapsed on load and a maxDepth of 2. The root object remains open; click ▶ to expand deeper nodes.
{ key: 'meta', renderAs: 'jsonPreview', renderAsOptions: { defaultCollapsed: true, maxDepth: 2 } }
String Values and Invalid JSON
When the field value is a string, the renderer attempts to parse it as JSON. A valid JSON string is expanded into a tree. A string that fails to parse renders as a styled error block — it does not throw.
Aurora's value is a valid JSON string — rendered as a tree. Mateo and Priya have invalid strings — each renders a red error block showing the raw value.
// Valid JSON string — parsed and rendered as an interactive tree
{ key: 'raw', renderAs: 'jsonPreview' } // value: '{"team": "platform"}'
// Invalid JSON string — renders a red error block, does not throw
{ key: 'raw', renderAs: 'jsonPreview' } // value: '{broken json'
Options Reference
| Option | Type | Default | Effect |
|---|---|---|---|
defaultCollapsed | boolean | true | Collapse nested nodes on initial render. The root object stays expanded. |
maxDepth | number | 3 | Truncates nested structures beyond this depth. Must be ≥ 0. |
className | string | unset | Additional CSS class on the root element. |
Caveats
- String values are attempted to be parsed as JSON. A successful parse renders the structure as an interactive tree. A failed parse renders a styled red error block (
Invalid JSON: <raw value>) — it does not throw. - The root object or array is always expanded regardless of
defaultCollapsed. Only nodes at depth > 0 are affected. - Negative
maxDepthvalues are clamped to 0, which renders only the root level with all children truncated as[...]or{...}. formattercan pre-process the value before rendering. Use it to extract a sub-field from an object, or to normalize a raw string before JSON parsing.- The JSON tree is read-only — values are not editable in-place.