Components
JSON viewer
NativeInspect structured data with native nested disclosures and wrapping values.
$Object ยท 4 entries
deployment:"release-2026-11"
status:"ready"
regionsArray ยท 2 entries
0:"London"
1:"Singapore"
checksObject ยท 2 entries
accessibility:true
failures:null
Installation
npx nook-ui@latest add json-viewerPrompt
Paste this into your AI coding assistant. It adds this exact component, the same way the CLI does, and tells the assistant how to use it.
Short. For assistants that can run commands in your project.
Add the Nook "JSON viewer" component to this project, exactly as Nook ships it.
Inspect structured data with native nested disclosures and wrapping values.
Steps
1. Check for `nook.json` in the project root. If it is missing, run `npx nook-ui@latest init` first (React or Next.js with Tailwind CSS v4). It adds the Nook tokens, the theme and `cn()`.
2. Run `npx nook-ui@latest add json-viewer`. It writes `components/ui/json-viewer.tsx` together with everything the component needs. Do not write the component from memory.
3. If you cannot run commands, fetch http://localhost:3000/r/json-viewer.json, write every entry of `files` to the path it names, install the packages in `dependencies`, and repeat for each name in `registryDependencies`.
4. Use it where I ask. Start from this example:
```tsx
import { JsonViewer } from "@/components/ui/json-viewer";
export default function Example() {
return <div className="grid w-full max-w-xl min-w-0 gap-4"><JsonViewer label="Deployment response" value={{ deployment: "release-2026-11", status: "ready", regions: ["London", "Singapore"], checks: { accessibility: true, failures: null } }} /></div>;
}
```
API
- `JsonViewer`: Inspect structured data with native nested disclosures and wrapping values.
- `value` (`JsonValue`): JSON-compatible value to inspect.
- `label` (`string`): Region name; defaults to JSON data.
- `defaultExpandedDepth` (`number`): Initially open levels; defaults to 1.
- `maxDepth` (`number`): Stops recursion at this depth; defaults to 20. Circular ancestors are labelled.
- `...props` (`React.HTMLAttributes`): Native attributes on the root, with className merged and ref forwarded.
Rules
- Colors, radii, shadows and motion come from Nook tokens and classes such as `bg-primary`, `text-muted-foreground`, `border-border`, `rounded-lg` and `h-control`. Never hard-code them.
- Do not restyle or simplify the file. Change how it looks through `className`, its props and the theme.
- It must keep working with the keyboard, in light and dark mode, and in the sharp, soft and bold styles.
- Accessibility: Native details and summary work with Enter and Space. A named region contains a text representation.
Done when the component renders like the example in light and dark mode and the project type-checks.Usage
import { JsonViewer } from "@/components/ui/json-viewer";
export default function Example() {
return <div className="grid w-full max-w-xl min-w-0 gap-4"><JsonViewer label="Deployment response" value={{ deployment: "release-2026-11", status: "ready", regions: ["London", "Singapore"], checks: { accessibility: true, failures: null } }} /></div>;
}Examples
A failed request
$Object ยท 3 entries
status:422
errorObject ยท 3 entries
code:"invalid_email"
message:"The email address is not valid."
field:"billing.contact.email"
requestId:"req_7d1f09aa-3b2e-4a3c-9c6d-88d1c0a4e2f1"
Webhook payload
$Object ยท 6 entries
id:"evt_1QxZ8a"
type:"invoice.paid"
created:1731744000
dataObject ยท 1 entry
objectObject ยท 6 entries
id:"in_0041"
customer:"cus_Mj3k"
amount_paid:45000
currency:"usd"
linesArray ยท 1 entry
0Object ยท 2 entries
description:"Team plan, 12 seats"
amount:45000
paid:true
livemode:false
request:null
Collapsed feature flags
$Object ยท 3 entries
checkoutObject ยท 3 entries
newPayments:true
applePay:false
rolloutArray ยท 3 entries
0:10
1:25
2:50
searchObject ยท 2 entries
fuzzy:true
maxResults:20
betaObject ยท 2 entries
usersArray ยท 2 entries
0:"maya@acme.com"
1:"imran@acme.com"
expires:"2026-12-31"
Depth limit
$Object ยท 1 entry
companyObject ยท 2 entries
name:"Acme"
teamsObject ยท 2 entries
design: [Depth limit reached]
engineering: [Depth limit reached]
Empty response
$Object ยท 3 entries
dataArray ยท 0 entries
Empty array
total:0
nextCursor:null
Props
JsonViewer
Inspect structured data with native nested disclosures and wrapping values.
| Prop | Type | Default | Description |
|---|---|---|---|
| value | JsonValue | โ | JSON-compatible value to inspect. |
| label | string | โ | Region name; defaults to JSON data. |
| defaultExpandedDepth | number | โ | Initially open levels; defaults to 1. |
| maxDepth | number | โ | Stops recursion at this depth; defaults to 20. Circular ancestors are labelled. |
| ...props | React.HTMLAttributes | โ | Native attributes on the root, with className merged and ref forwarded. |
Accessibility
Native details and summary work with Enter and Space. A named region contains a text representation.
Checked against WCAG 2.1 AA with automated axe tests and keyboard tests on every release.