Skip to content
Haze UI

JSON viewer

An expandable JSON tree with key and value search, native page disclosures and copying for the selected value or path.

pnpm dlx shadcn@latest add @haze/json-viewer
Open preview in a new tab
Livesmall script

When to use

  • Readers inspect nested webhook events or API responses.
  • People need to find a field and copy its exact property path or JSON value.

When not to use

  • Use code-block for a read-only source listing.
  • Use file-tree for project directories.

Installation

Add the Haze registry to components.json once, then install JSON viewer with the shadcn CLI. Works in any Astro project with Tailwind CSS v4.

pnpm dlx shadcn@latest add @haze/json-viewer
First time? Registry and theme setup

1. Add to components.json:

{
  "registries": {
    "@haze": "http://localhost:4329/r/{name}.json"
  }
}

2. Install the theme once: npx shadcn@latest add @haze/theme, then import it after Tailwind in your global CSS:@import "./haze.css";

API reference

PropTypeDefaultDescription
id*string–Unique prefix for the viewer label and search field.
data*JSON value–A JSON object, array, string, number, boolean or null.
labelstringJSON payloadVisible name of the payload.
rootNamestringpayloadRoot label used when copying property paths.
openDepthnumber1Number of nesting levels initially expanded.
pageSizenumber40Children per disclosure in a large array or object.
classstring–Classes applied to the viewer panel.

Keyboard interactions

EnterSpace
Toggle the focused branch or page.
Arrow keysHomeEnd
Move across visible rows, open a branch or return to its parent.
EnterShiftEnter in search
Select the next or previous match.

Accessibility

  • Branches use native summaries. Each key and scalar renders as escaped text.
  • Search reports matches politely. A selectable text field is available when copying fails.

Notes for AI

Copy into Claude Code, Cursor, Codex or any coding agent. Agents can also read the Markdown version of this page.

  • Install and use

    Install the Haze UI component "JSON viewer" with `npx shadcn@latest add @haze/json-viewer`. If components.json has no "@haze" registry yet, add "registries": { "@haze": "http://localhost:4329/r/{name}.json" }. If src/styles/haze.css does not exist yet, run `npx shadcn@latest add @haze/theme` once and import it from the global stylesheet after Tailwind. The CLI stops at an overwrite question when a Haze file already exists and differs, even with --yes, and then installs nothing after it: read its output. If the user has not edited their Haze files, re-run with --overwrite to take the registry versions; if they have, ask them before overwriting. Then import JsonViewer from "@/components/haze/ui/json-viewer.astro" (or the relative path) and render it where it fits the page. Keep Haze token classes (bg-background, text-muted-foreground, border-border...) and never hardcode colors. Docs: http://localhost:4329/ui/json-viewer.md

  • Customize with real content

    Adapt the Haze json-viewer ui for our product. Replace the demo values of these props with our real content: id, data, label, rootName, openDepth, pageSize, class. Keep the layout, the heading level rules and these accessibility details: Branches use native summaries. Each key and scalar renders as escaped text. Search reports matches politely. A selectable text field is available when copying fails. Do not add raw color classes; use the Haze tokens.

  • Choose the right block

    Before using json-viewer, check it fits: use it when readers inspect nested webhook events or api responses.; people need to find a field and copy its exact property path or json value.. Avoid it when use code-block for a read-only source listing.; use file-tree for project directories.. Alternatives: @haze/code-block, @haze/file-tree, @haze/copy-button.

Dependencies

  • npm: @lucide/astro
  • @haze/button
  • @haze/search-field
  • @haze/utils
  • @haze/theme (one-time setup)

Source · Original Haze UI work.

Catalog

↑↓ moveEnter openEsc close

Keyboard shortcuts

CtrlK
Command palette
/
Focus search
←↑→↓
Move between cards
jk
Next / previous card
ci
Copy code / install command (detail page)
[]
Previous / next entry
?
This help
Esc
Close dialog