JSON View
Read-only JSON tree inspector on @uiw/react-json-view, with optional Source via Code Block.
Plus Registry
This component ships from registry.plus.json. Configure @f-ui-plus on the Installation page. Install code-block first (dependency), then @f-ui-plus/json-view.
The json-view registry item provides JsonView: a Tree inspector for objects and arrays (collapse, types, node copy). The tree engine is @uiw/react-json-view (pinned 2.0.0-alpha.43). f-ui wraps display only — we do not ship @uiw/react-json-view/editor. chrome (off by default, same as Code Block) adds a Tree | Source bar and an always-visible Copy. Source reuses Code Block. It is read-only — not a JSON editor and not a Formily field.
When To Use
- Inspect a parsed blob the operator did not author: task payload or result, workflow step I/O, API request and response in process history.
- Prefer Code Block alone for logs, traceback text, or a JSON file the operator will copy as a document.
- Prefer Descriptions when keys are a known schema (status, id, amount) rather than a free-form object.
- Do not use this as a fill-in control. There is no edit mode in v1.
Features
| Area | Behavior |
|---|---|
| Tree | @uiw/react-json-view paints the object graph. Default collapse depth is 2 (root plus one level). Type labels and object sizes follow DevTools. |
| Chrome | Off by default. chrome shows Tree | Source and Copy in a header (Code Block twin). The tree’s own node copy stays; there is no second hover Copy on the slab. |
| Source | Pretty JSON in Code Block. Requires chrome to toggle; or pass defaultView="source". |
| Copy | Tree: per-node copy from the engine. chrome: toolbar copies the full pretty JSON (needed for Source, which has no node copy). |
| Theme | Follows the app light/dark theme. No theme prop. |
| Empty / error | null / undefined → Empty. Invalid JSON string or a circular structure → Result error. |
Installing
Configure @f-ui-plus and FUI_PLUS_REGISTRY_TOKEN as in Installation — Plus Registry.
FUI_PLUS_REGISTRY_TOKEN=xxx pnpm dlx shadcn@latest add @f-ui-plus/json-viewFUI_PLUS_REGISTRY_TOKEN=xxx npx shadcn@latest add @f-ui-plus/json-viewFUI_PLUS_REGISTRY_TOKEN=xxx yarn dlx shadcn@latest add @f-ui-plus/json-viewFUI_PLUS_REGISTRY_TOKEN=xxx bun x shadcn@latest add @f-ui-plus/json-viewregistryDependencies: code-block, Empty, Result, Copy Affordance. Runtime: @uiw/react-json-view@2.0.0-alpha.43 (pin the alpha), next-themes.
Usage
import { JsonView } from "@/components/f-ui/json-view/json-view";
export function Example({ payload }: { payload: unknown }) {
return <JsonView value={payload} />;
}Examples
Minimal (Default)
A payload card: tree only, no header. Copy a node from the tree itself.
"use client"
import { JsonView } from "@/components/f-ui/json-view/json-view"
const TASK_RESULT = {
status: "succeeded",
durationMs: 1840,
output: {
ticketId: "INC-1042",
assignee: { id: "u_9", name: "Ada" },
steps: [
{ name: "classify", ok: true },
{ name: "notify", ok: true, skipped: false },
],
},
error: null,
}
export function JsonViewDemo() {
return <JsonView value={TASK_RESULT} />
}Chrome
Turn on chrome for Tree | Source and a pinned Copy — same rhythm as Code Block chrome.
"use client"
import { JsonView } from "@/components/f-ui/json-view/json-view"
export function JsonViewDemoChrome() {
return (
<JsonView
chrome
value={{
status: "succeeded",
output: { ticketId: "INC-1042", assignee: { id: "u_9", name: "Ada" } },
}}
/>
)
}JSON String
Hosts that stored the body as a string can pass it through. JsonView parses it; invalid text is an error, not a tree.
"use client"
import { JsonView } from "@/components/f-ui/json-view/json-view"
const WIRE = `{
"method": "POST",
"path": "/api/tickets",
"body": { "title": "Printer offline", "priority": "high" }
}`
export function JsonViewDemoJsonString() {
return <JsonView value={WIRE} />
}Edge Cases & Errors
Empty Value
null and undefined are a successful empty inspect — Empty, not an error. Copy is hidden.
No JSON to display
Pass an object, array, or JSON string.
"use client"
import { JsonView } from "@/components/f-ui/json-view/json-view"
export function JsonViewDemoEmpty() {
return <JsonView value={null} />
}Invalid JSON
A string that does not parse shows Result with recovery-free copy (fix the producer, not the viewer).
This is not valid JSON.
"use client"
import { JsonView } from "@/components/f-ui/json-view/json-view"
export function JsonViewDemoInvalidJson() {
return <JsonView value="{not json" />
}Circular objects also fail Result: they cannot be serialized for Source or copy-all.
API Reference
Props
| Prop | Type | Default | Description |
|---|---|---|---|
value | unknown | (required) | Object, array, JSON string, or primitive. |
collapsed | boolean | number | 2 | Collapse depth passed to the tree engine. |
defaultView | "tree" | "source" | "tree" | Uncontrolled initial view. Primitives always paint Source. |
view | "tree" | "source" | — | Controlled view. |
onViewChange | (view) => void | — | View change callback. |
chrome | boolean | false | Header with Tree | Source and Copy. Off = tree slab; node copy comes from the engine. |
showSourceToggle | boolean | true | Hide the Tree | Source segment when chrome. |
showCopy | boolean | true | Hide chrome copy-all. Node copy on the tree can remain. |
displayDataTypes | boolean | true | Type labels on values. |
displayObjectSize | boolean | true | Object / array size. |
objectSortKeys | boolean | false | Keep wire key order unless true. |
highlightUpdates | boolean | true | Flash nodes when value changes (live progress). |
maxHeightClassName | string | "max-h-96" | Shared scroll cap for Tree and Source. |
className | string | — | Outer container. |