Json Tree
import { JsonTree } from '@hanzo/ui'
Default
Two levels open, the rest behind a count, with Expand all, Collapse all and Copy.
Response
{5 keys}
id:"dec_8f2c"
model:"kai"
answers:{2 keys}
team:{4 keys}
critical:{3 keys}
usage:{2 keys}
input_tokens:61
output_tokens:0
latency_ms:18.4
export function Default() {
return <JsonTree data={RESPONSE} title="Response" />
}Closed
`depth={0}` starts with only the root row.
JSON
{5 keys}
export function Closed() {
return <JsonTree data={RESPONSE} depth={0} />
}Types
export type JsonTreeVariant = 'code' | 'boxed'export type JsonHighlight = 'blue' | 'red' | 'partial-blue'export type JsonTreeLabels = {
emptyString?: string
emptyArray?: string
emptyObject?: string
}export type JsonTreeEntry = { id: string; label: string; value: unknown }export type Sifted = { rows: Map<string, boolean>; open: Set<string> }export interface JsonTreeProps extends Omit<YStackProps, 'children' | 'minHeight' | 'maxHeight'> {
/** The value to draw — anything `JSON.stringify` accepts. Ignored when `entries` is given. */
data?: unknown
/** A labelled root: each entry a top-level node drawn with its label. */
entries?: JsonTreeEntry[]
/** `code` (default) or the record kit's `boxed`. */
variant?: JsonTreeVariant
/** How a node is marked, by its dotted keyPath. */
getNodeHighlighting?: (keyPath: string) => JsonHighlight | null | undefined
/** Makes every leaf a button; told the value and its dotted keyPath. */
onNodeValueClick?: (value: unknown, keyPath: string) => void
/** The words the tree says. */
labels?: JsonTreeLabels
/** How many levels are open on first paint. */
depth?: number
/** The header's title. Omit it, `showCopyButton={false}` and `search={false}` to drop the header. */
title?: string
showCopyButton?: boolean
/** Whether the header has a filter box. Defaults to true. */
search?: boolean
/** The tallest the tree grows on its own, in px; past it the tree scrolls. */
maxHeight?: number
/** The shortest a drag makes it, in px. */
minHeight?: number
/** Whether a footer grip resizes the tree. */
resizable?: boolean
/** A height to start from, as `onResize` last reported it. */
defaultHeight?: number | null
/** Every height the reader drags to, and `null` when a double-click hands it back. */
onResize?: (height: number | null) => void
}Exports
JsonTreetype JsonTreeProps