JSON to read and explore: folding objects and arrays, colored values, copy.
$ pnpm dlx shadcn@latest add @dashral/json-viewerInstallation
$ pnpm dlx shadcn@latest add @dashral/json-viewerAdds the component, the components it builds on, its npm packages and the theme tokens it uses. Or by its full URL: https://dashral.com/r/json-viewer.json
Usage
import { JsonViewer } from "@/components/dashral/json-viewer"
<JsonViewer data={event.payload} name="payload" />Using the npm package? Import from @dashral/ui/components/json-viewer instead, here and in the examples; the rest is the same.
Examples
API reference
JsonViewer
Also takes every prop of <div>(opens in a new tab).
| Prop | Type | Default |
|---|---|---|
data | unknownAny JSON value, or a JSON string (parsed). Required. | — |
name | stringA key for the root. | — |
defaultExpandDepth | numberHow many levels open at first; 0 starts it folded. | 1 |
pageSize | numberPast this many items in one array or object, a "Show N more" button. | 100 |
copyable | booleanA copy button for the whole value, as indented JSON. | true |
maxHeight | number | stringScrolls past this height. | — |
className | stringExtra classes, merged with cn() so yours win. | — |
Keyboard
| Keys | Action |
|---|---|
| Tab | Move between the foldable rows |
| EnterorSpace | Fold or unfold a row |
Accessibility
- Each object and array is a button with aria-expanded; folded children are inert, out of the tab order.
- Folded rows say their size ("3 keys", "12 items"), in the page's language.
- Always left to right, Arabic pages included.
Motion
- Children grow open and fold shut by their height, fading as they go (--duration-standard); the chevron turns on the spring.