JSON viewer

A parsed JSON value, coloured by type, with every object and array foldable. It takes the value, not its text, so the colours come from the types and need no grammar. Text that only looks like JSON stays a CodeBlock.

Reach for it

A payload, a metadata object or an API error the user reads to understand what happened.

Not for

Text that is not JSON, or JSON the user edits. That is a CodeBlock or a Textarea.

A payload, and the copy button that belongs to it

Open to every level, because the reader came to see the value. Strings, numbers, booleans and null each take a colour, and the punctuation steps back. The copy button writes the value as indented JSON, the same text a developer would paste into a ticket.

{
    "reference":"INV-2024-0042",
    "amount":1250,
    "currency":"EUR",
    "isPaid":false,
    "paidAt":null,
    "debtor":{
      "siren":"552100554",
      "name":"Atelier Martin"
    },
    "tags":[
      "priority",
      "insured"
    ]
}

Without a copy button

The copy button needs both of its names or neither, as on CodeBlock. With neither, there is no button and no space kept for one.

{
    "code":"INSUFFICIENT_FUNDS",
    "retryable":true,
    "attempts":3
}

API reference

JsonViewer

PropTypeDefaultDescription
data*object-The parsed value. An object or an array: a lone scalar has nothing to fold or colour against.
label*string-Names the tree for assistive technology, e.g. "Payout error payload".
collapseLabel*string-Names the fold button of an open node, e.g. "Collapse".
expandLabel*string-Names the fold button of a closed node, e.g. "Expand".
copyLabel*string-Names the copy button at rest, and its presence is what adds one.
copiedLabel*string-Names it during the confirmation, e.g. "Copied".
data-testidstring-Names the element for a test. Never rendered, never announced.
height'capped' | 'fill'capped