Tally UI

JsonTree

Inspect a record's keys and values in an expandable, read-only JSON tree.

Import

import { JsonTree } from '@tallyui/components';

Usage

const order = { id: 7, billing: { city: 'Paris' }, items: [1, 2] };

<JsonTree value={order} />

As in WCPOS v2, the root starts open and containers past depth 1 start closed. Each container shows its size as “N items” (or “1 item”), from the catalogue's json_tree.items_one and json_tree.items_other plural keys, and values have no type labels. A container's accessible name is its key and that count, never the arrow. A down arrow (▾) marks an open container; a right arrow (▸) marks a closed or empty one.

Strings longer than 30 characters show the first 30 followed by .... The string is a button: press it to show the full value, and press again to shorten it.

Props

PropTypeDefaultDescription
valueunknownRequiredRecord or value to inspect. An undefined root shows emptyText.
collapsednumber1Containers deeper than this level start closed. The root is level 1.
emptyTextstring'No data'Text shown when value is undefined.
copyText(text: string) => void—Given, every node gets a copy button named “Copy” and its key (“Copy all” at the root), and the host supplies the clipboard, as v2's enableClipboard. A leaf passes its shown text (a string unquoted and in full); a container passes its JSON with two-space indent, undefined and functions dropped, NaN and Infinity as null, cycles as "[Circular]", and bigints as "2n".
classNamestring—Classes for the root view.
testIDstring'json-tree'Identifies the root view and prefixes the IDs -toggle-<path> (containers), -string-<path> (long strings) and -copy-<path> (copy buttons).

On this page