# JSON viewer

Inspect valid JSON as a searchable keyboard tree or exact read-only source with paths and consumer-owned copy actions.

Access: pro. Category: Data. Kind: composite.

## When to use

- Use it when a page needs inspect valid json as a searchable keyboard tree or exact read-only source with paths and consumer-owned copy actions.
- Choose it when the data structure, labels, and state are supplied by the application and must remain consumer controlled.

## Alternatives

- Choose data-table instead when sortable column controls, native row selection and a scrollable table is the actual interface need, rather than json viewer.

## Setup for agents

Use React 19 and TypeScript. Initialize shadcn for your framework, then merge this exact entry into components.json:

```json
{
  "registries": {
    "@tidal-pro": {
      "url": "https://tidalui.com/r/pro/{name}.json",
      "headers": {
        "Authorization": "Bearer ${TIDALUI_TOKEN}"
      }
    }
  }
}
```

The namespace must be named **@tidal-pro** because transitive Pro dependencies use that namespace. Obtain an agent key from your active Pro account at https://tidalui.com/account. Keep TIDALUI_TOKEN in your local environment, never in components.json, client code, Git or logs.

```sh
export TIDALUI_TOKEN='your-private-agent-key'
npx shadcn@latest add @tidal-pro/waitlist-form
npx shadcn@latest add https://tidalui.com/r/tidal-button.json
```

Free command: `npx shadcn@latest add https://tidalui.com/r/<name>.json`.
Pro command: `npx shadcn@latest add @tidal-pro/<name>`.

Import the base stylesheet and every stylesheet listed on the installed item's metadata. For example:

```tsx
import "./components/ui/tidal.css";
import "./components/ui/hero-section.css";
// Place installed components inside this wrapper:
<div className="tidal-scope" data-theme="dark">...</div>
```

Omit data-theme for the default light theme. Put the attribute on the same tidal-scope element for dark mode. Every component installs the shared free tidal-base dependency. After upgrading, run `npx shadcn@latest add https://tidalui.com/r/tidal-base.json --overwrite` to receive current tokens. Review local modifications before overwriting.

Vite: Use React + TypeScript. Map @/* to ./src/* in paths and Vite resolve.alias. Import tidal.css and each component stylesheet in your application entry.

Next.js 15 App Router: Next.js App Router: import tidal.css and component CSS in app/layout.tsx. Interactive examples belong in a client component with "use client". Map @/* to ./* or ./src/* to match your project.

TypeScript 6: use paths without baseUrl:

```json
{
  "compilerOptions": {
    "paths": {
      "@/*": [
        "./src/*"
      ]
    }
  }
}
```

Pro registry requests are server/CLI-only. Use the same-origin account interface in a browser; cross-origin Authorization preflights are intentionally unsupported.


## Install JSON viewer

```sh
npx shadcn@latest add @tidal-pro/json-viewer
```

Stylesheets: `components/ui/tidal.css`, `components/ui/json-viewer.css`.

## Minimal example

```tsx
import"./components/ui/tidal.css";
import"./components/ui/json-viewer.css";
import{TidalJsonViewer}from"./components/ui/json-viewer";
export default()=><div className="tidal-scope"><TidalJsonViewer expandedPaths={["value"]} label={"Demo"} onExpandedPathsChange={() => {}} onSelectedPathChange={() => {}} onViewChange={() => {}} selectedPath={"value"} value={"value"} view={"source"}/></div>;
```

## Structured props

- `TidalJsonViewer.expandedPaths: ReadonlyArray<string>`: Required expanded paths value accepted by this exported component.
- `TidalJsonViewer.label: string`: Required label value accepted by this exported component.
- `TidalJsonViewer.onExpandedPathsChange: (paths: readonly string[], path: string, value: TidalJsonValue, event: TidalTreeInteractionEvent | MouseEvent<HTMLButtonElement>) => void`: Callback invoked when the expanded paths change interaction is proposed.
- `TidalJsonViewer.onSelectedPathChange: (path: string, value: TidalJsonValue, event: TidalTreeInteractionEvent) => void`: Callback invoked when the selected path change interaction is proposed.
- `TidalJsonViewer.onViewChange: (view: TidalJsonView, event: MouseEvent<HTMLButtonElement>) => void`: Callback invoked when the view change interaction is proposed.
- `TidalJsonViewer.selectedPath: string | null`: Required selected path value accepted by this exported component.
- `TidalJsonViewer.value: TidalJsonValue`: Required value value accepted by this exported component.
- `TidalJsonViewer.view: TidalJsonView`: Required view value accepted by this exported component.
- `TidalJsonViewer.copyButtonProps?: NativeButtonProps | undefined`: Optional copy button props value accepted by this exported component.
- `TidalJsonViewer.copyButtonRef?: Ref<HTMLButtonElement> | undefined`: Optional copy button ref value accepted by this exported component.
- `TidalJsonViewer.description?: ReactNode`: Optional description value accepted by this exported component.
- `TidalJsonViewer.dir?: "ltr" | "rtl" | undefined` (default "ltr"): Optional dir value accepted by this exported component.
- `TidalJsonViewer.disabled?: boolean | undefined` (default false): Optional disabled value accepted by this exported component.
- `TidalJsonViewer.headingLevel?: TidalJsonHeadingLevel | undefined` (default "h3"): Optional heading level value accepted by this exported component.
- `TidalJsonViewer.labels?: Partial<TidalJsonViewerLabels> | undefined`: Optional labels value accepted by this exported component.
- `TidalJsonViewer.maxStringLength?: number | undefined` (default 120): Optional max string length value accepted by this exported component.
- `TidalJsonViewer.onCopyRequest?: ((request: TidalJsonCopyRequest, event: MouseEvent<HTMLButtonElement>) => void) | undefined`: Callback invoked when the copy request interaction is proposed.
- `TidalJsonViewer.onQueryChange?: ((query: string, event: ChangeEvent<HTMLInputElement>) => void) | undefined`: Callback invoked when the query change interaction is proposed.
- `TidalJsonViewer.query?: string | undefined` (default ""): Optional query value accepted by this exported component.
- `TidalJsonViewer.searchInputProps?: SearchInputProps | undefined`: Optional search input props value accepted by this exported component.
- `TidalJsonViewer.searchInputRef?: Ref<HTMLInputElement> | undefined`: Optional search input ref value accepted by this exported component.
- `TidalJsonViewer.sourceButtonProps?: NativeButtonProps | undefined`: Optional source button props value accepted by this exported component.
- `TidalJsonViewer.sourceButtonRef?: Ref<HTMLButtonElement> | undefined`: Optional source button ref value accepted by this exported component.
- `TidalJsonViewer.sourceMaxHeight?: number | undefined` (default 420): Optional source max height value accepted by this exported component.
- `TidalJsonViewer.treeButtonProps?: NativeButtonProps | undefined`: Optional tree button props value accepted by this exported component.
- `TidalJsonViewer.treeButtonRef?: Ref<HTMLButtonElement> | undefined`: Optional tree button ref value accepted by this exported component.
- `TidalJsonViewer.treeRef?: Ref<HTMLDivElement> | undefined`: Optional tree ref value accepted by this exported component.

## Complete usage example

[Source](https://tidalui.com/examples/json-viewer.tsx) | [Manifest](https://tidalui.com/examples/json-viewer.json). Install the listed additional dependencies. Consumer fixture: TypeScript pass; Vite pass. This fixture check is distinct from the actual shadcn install receipt.

```tsx
"use client";

import "./components/ui/tidal.css";

import { useState } from "react";

import { TidalJsonViewer, type TidalJsonCopyRequest, type TidalJsonView } from "./components/ui/json-viewer";

import "./components/ui/json-viewer.css";

import "./components/ui/tree-view.css";

import "./components/ui/code-block.css";



const tidalExampleStyles = ".tidal-scope .json-viewer-demo {\n  display: grid;\n  width: 100%;\n  max-width: 760px;\n  min-width: 0;\n  gap: 14px;\n}\n\n.json-viewer-demo-footer {\n  display: flex;\n  min-width: 0;\n  align-items: center;\n  justify-content: space-between;\n  gap: 12px;\n  padding-inline: 4px;\n}\n\n.json-viewer-demo-footer p {\n  min-width: 0;\n  margin: 0;\n  color: var(--t-muted);\n  font-size: 11px;\n  line-height: 1.45;\n  overflow-wrap: anywhere;\n}\n\n.json-viewer-demo-footer button {\n  flex: 0 0 auto;\n  min-width: 44px;\n  min-height: 44px;\n  border: 1px solid var(--t-border);\n  border-radius: var(--t-radius-control);\n  padding-inline: 14px;\n  color: var(--t-ink);\n  background: var(--t-surface);\n  cursor: pointer;\n  font: inherit;\n  font-size: 12px;\n  font-weight: 680;\n}\n\n.json-viewer-demo-footer button:hover {\n  background: var(--t-wash);\n}\n\n.json-viewer-demo-footer button:focus-visible {\n  outline: 2px solid var(--t-ink);\n  outline-offset: 2px;\n}\n\n@media (max-width: 420px) {\n  .json-viewer-demo-footer {\n    display: grid;\n  }\n\n  .json-viewer-demo-footer button {\n    width: 100%;\n  }\n}\n\n@media (prefers-reduced-motion: reduce) {\n  .json-viewer-demo-footer button {\n    transition: none;\n  }\n}";

const samplePayload = {
  id: "evt_01JAF7M8",
  type: "workspace.member.updated",
  createdAt: "2026-10-14T21:45:00-05:00",
  data: {
    workspaceId: "ws_sample",
    customer: {
      id: "cus_sample_42",
      name: "Ava Reed",
      email: "ava@example.test",
      active: true,
    },
    permissions: ["projects:read", "comments:write"],
    attempts: 2,
    note: null,
  },
} as const;

const initialExpanded = ["", "/data", "/data/customer"];

export function JsonViewerDemo({ dir = "ltr" }: { dir?: "ltr" | "rtl" }) {
  const [view, setView] = useState<TidalJsonView>("tree");
  const [expandedPaths, setExpandedPaths] =
    useState<readonly string[]>(initialExpanded);
  const [selectedPath, setSelectedPath] = useState<string | null>(
    "/data/customer/name",
  );
  const [query, setQuery] = useState("");
  const [status, setStatus] = useState(
    "Select a value, search the payload or copy exact JSON.",
  );

  async function copyJson(request: TidalJsonCopyRequest) {
    if (!navigator.clipboard?.writeText) {
      setStatus("Clipboard access is unavailable in this preview.");
      return;
    }
    try {
      await navigator.clipboard.writeText(request.text);
      setStatus(
        `${request.displayPath} copied (${request.text.length} characters).`,
      );
    } catch {
      setStatus("The browser did not allow this copy. Try again.");
    }
  }

  return (
    <section className="json-viewer-demo" aria-label="JSON viewer sample">
      <TidalJsonViewer
        label="Webhook delivery"
        description="Inspect the exact fictional payload before using it elsewhere."
        dir={dir}
        value={samplePayload}
        view={view}
        onViewChange={(nextView) => {
          setView(nextView);
          setStatus(
            `${nextView === "tree" ? "Tree" : "Source"} view selected.`,
          );
        }}
        expandedPaths={expandedPaths}
        onExpandedPathsChange={(nextPaths) => setExpandedPaths(nextPaths)}
        selectedPath={selectedPath}
        onSelectedPathChange={(nextPath, _value) => {
          setSelectedPath(nextPath);
          setStatus(`${nextPath || "$"} selected.`);
        }}
        query={query}
        onQueryChange={setQuery}
        onCopyRequest={copyJson}
      />

      <footer className="json-viewer-demo-footer">
        <p role="status">{status}</p>
        <button
          type="button"
          onClick={() => {
            setView("tree");
            setExpandedPaths(initialExpanded);
            setSelectedPath("/data/customer/name");
            setQuery("");
            setStatus("The local sample was reset.");
          }}
        >
          Reset sample
        </button>
      </footer>
    </section>
  );
}

export default function AgentExample() {
  return (
    <div className="tidal-scope" data-theme="light" dir="ltr">
      <style>{tidalExampleStyles}</style>
      <JsonViewerDemo />
    </div>
  );
}

```

## Gotchas

- Supply truthful data and labels; the component does not fetch, aggregate, or persist records.

## Theme and accessibility

{"tokens":["--t-accent","--t-border","--t-border-strong","--t-canvas","--t-danger","--t-display","--t-ease-out","--t-ease-spring","--t-faint","--t-font","--t-ink","--t-line","--t-muted","--t-primary","--t-primary-contrast","--t-radius-card","--t-radius-control","--t-radius-overlay","--t-radius-panel","--t-ring","--t-shadow-lg","--t-shadow-soft","--t-soft","--t-subtle","--t-surface","--t-wash"],"darkMode":true}

{"keyboard":["Tab and Shift+Tab follow the component's native focus order.","Arrow-key behavior follows the exported composite-control implementation."],"aria":"The component wires labels and relationships from consumer-provided visible text or ARIA props; preserve those labels in production.","notes":"Verify focus visibility, text alternatives, contrast, and reduced motion in the final composition."}

label and optional description/headingLevel name the viewer. value accepts JSON primitives, arrays, or plain JSON objects; circular references, sparse arrays, accessors, symbols, nonfinite numbers, class instances, and nesting beyond the documented safety boundary render a localized configuration alert rather than being evaluated. view/onViewChange controls Tree or Source. expandedPaths/onExpandedPathsChange and selectedPath/onSelectedPathChange use RFC 6901 JSON Pointer strings, including the empty root path; display paths remain readable $.property/[index] labels. Optional controlled query/onQueryChange searches full keys, primitive values, and display paths, highlights visible matches, and temporarily reveals matching ancestors. maxStringLength bounds visible tree strings while exact values remain available to the copy adapter and source view. onCopyRequest receives the exact path, display path, JSON value, and serialized text; the component never touches the clipboard. disabled, dir, localized labels, native section/search/view/copy attrs and refs, tree ref, sourceMaxHeight, className and remaining safe section attributes are supported. Native handlers run before view/search/copy callbacks and may prevent proposals. The component performs no parsing, evaluation, logging, request, storage, clipboard write, or persistence.
