Skip to content

jsonToTree

widgetsdisplay

Convert any JSON-compatible value to a TreeNode, optionally prefixed by `key` (the property name or array index in the parent container)

Installation

$ bunx termuijs add json-to-tree

Copies the source into src/components/json-to-tree/ and installs @termuijs/core, @termuijs/widgets.

Usage

ts
import { jsonToTree } from '@termuijs/widgets'
ts
new jsonToTree(options: JSONViewOptions, style: Partial<Style> = {})

API Reference

jsonToTree

PropTypeRequiredDescription
dataunknownrequiredThe JSON value to display
onSelect(node: TreeNode, path: number[]) => voidoptionalCallback when a leaf node is selected
indentnumberoptionalSpaces per indent level (default: 2)
#display#json-to-tree