Skip to content

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'

On this page
  1. An API answer
  2. Skeleton
  3. When to use it
  4. For everyone
  5. Props

An API answer

Two levels start open. Open and close the keys.

Response body
    • "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.

Headers
    • "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

JsonViewerTypeDefault
valuerequired unknown
open number 2
title string JSON
JsonViewerSkeletonTypeDefault
lines number 6
  1. An API answer
  2. Skeleton
  3. When to use it
  4. For everyone
  5. Props

    Search pages, sections and terms