JSON Viewer

View as Markdown

A JSON value as a tree to open, search and walk with the arrow keys, such as a webhook's payload or a tool call's result.

  • id:"evt_1Q8vR2"
  • type:"invoice.payment_failed"
  • created:1764926043
  • livemode:false
  • data:1 key
  • invoice:10 keys
  • id:"in_7HkQ2"
  • number:"INV-20419"
  • amount_due:480000
  • currency:"usd"
  • attempt_count:3
  • next_payment_attempt:null
  • request:2 keys
  • id:"req_Z1"
  • idempotency_key:null

When to use

A JSON value as a tree to open, search and walk with the arrow keys, such as a webhook's payload or a tool call's result. Use Code Block instead when people read the whole payload as text, without folding or searching it.

Usage

import { JsonViewer } from "./ui/uicontext/components/JsonViewer.ts"
export const Response = <M>(h: Html.H<M>, body: unknown) =>	JsonViewer(h, { props: { label: "Response", value: body, depth: 2, searchable: true } })

Examples

A tool call's input and result

depth sets how much starts open. An array over 100 items opens into ranges of 100.

Input

  • query:"status:open priority:high"
  • project:"ENG"
  • limit:50
  • fields:4 items
  • 0:"id"
  • 1:"title"
  • 2:"assignee"
  • 3:"updated"

Result

  • total:240
  • truncated:false

API reference

Props

JsonViewer props
NameTypeDefaultDescription
labelrequiredstring—What the value is, for screen readers: "Response body".
valuerequiredunknown—Any JSON value: an object, an array, or a single string, number, boolean or null.
depthnumber1How many levels start open; 1 by default.
searchableboolean—A search field and Expand all and Collapse all above the tree.
maxHeightnumber360The tree's tallest, in px, before it scrolls; 360 by default.

Installation

pnpm dlx shadcn@latest add checkfu/uicontext/json-viewer

Source