JsonViewer
JSON to read: objects and arrays open and close, values in the colours of code, and Copy for all of it.
import { JsonViewer, JsonViewerSkeleton } from '@sypnia/ui/react'
An API answer
Two levels start open. Open and close the keys.
- "id": "ord_1042"
- "status": "paid"
- "total": 128.4
- "currency": "USD"
- "refunded": false
- "note": null
- "id": "cus_77"
- "name": "Laura Méndez"
Code
import { JsonViewer } from '@sypnia/ui/react';
const body = {
id: 'ord_1042', status: 'paid', total: 128.4, currency: 'USD', refunded: false, note: null,
customer: { id: 'cus_77', name: 'Laura Méndez', address: { city: 'Medellín', country: 'CO' } },
items: [{ sku: 'TSHIRT-M', qty: 2 }, { sku: 'MUG', qty: 1 }],
};
// Two levels start open. Press a key with ▸ to open or close it; a closed one says how much it holds.
export default function Response() {
return <JsonViewer title="Response body" value={body} />;
} Skeleton
The real piece and its skeleton: the same box, so nothing moves when the data arrives.
- "content-type": "application/json"
- "x-request-id": "req_9c2e"
Code
import { JsonViewer, JsonViewerSkeleton } from '@sypnia/ui/react';
// While the response arrives.
export default function Skeleton() {
return (
<div className="sy-stack">
<JsonViewer title="Headers" value={{ 'content-type': 'application/json', 'x-request-id': 'req_9c2e' }} />
<JsonViewerSkeleton lines={4} />
</div>
);
} When to use it
Use it when
- An API answer, a webhook body, a saved setting.
Do not use it when
- The person must edit it: a form or a CodeBlock in an editor.
- It is a table of rows: DataTable.
For everyone
- Every object and array is a button that says whether it is open; a closed one says how many keys or items it holds.
- Empty values say
null, in their own colour and in words.
Props
| JsonViewer | Type | Default |
|---|---|---|
valuerequired | unknown | |
open | number | 2 |
title | string | JSON |
| JsonViewerSkeleton | Type | Default |
|---|---|---|
lines | number | 6 |