Blocks / JSON view

JSON view

Input or output data in mono, coloured by kind; scrolls, copies.

import { JsonView } from "@forgeron/ui";
/01 → Default
Output
{
  "id": 4182,
  "name": "Transalp",
  "amount": 9600,
  "won": true,
  "lost_reason": null
}
import { JsonView } from "@forgeron/ui";

export default function Default() {
  return (
    <div style={{ width: 320 }}>
      <JsonView
        label="Output"
        value={{ id: 4182, name: "Transalp", amount: 9600, won: true, lost_reason: null }}
      />
    </div>
  );
}
/02 → Long and empty
Input · 12 items
[
  {
    "order": "SO-4410",
    "weight": 20,
    "to": "Grenoble",
    "express": true
  },
  {
    "order": "SO-4411",
    "weight": 37,
    "to": "Lyon",
    "express": false
  },
  {
    "order": "SO-4412",
    "weight": 54,
    "to": "Annecy",
    "express": false
  },
  {
    "order": "SO-4413",
    "weight": 71,
    "to": "Grenoble",
    "express": false
  },
  {
    "order": "SO-4414",
    "weight": 88,
    "to": "Lyon",
    "express": true
  },
  {
    "order": "SO-4415",
    "weight": 105,
    "to": "Annecy",
    "express": false
  },
  {
    "order": "SO-4416",
    "weight": 122,
    "to": "Grenoble",
    "express": false
  },
  {
    "order": "SO-4417",
    "weight": 139,
    "to": "Lyon",
    "express": false
  },
  {
    "order": "SO-4418",
    "weight": 156,
    "to": "Annecy",
    "express": true
  },
  {
    "order": "SO-4419",
    "weight": 173,
    "to": "Grenoble",
    "express": false
  },
  {
    "order": "SO-4420",
    "weight": 190,
    "to": "Lyon",
    "express": false
  },
  {
    "order": "SO-4421",
    "weight": 207,
    "to": "Annecy",
    "express": false
  }
]
Output
Not run yet
import { JsonView } from "@forgeron/ui";

const orders = Array.from({ length: 12 }, (_, i) => ({
  order: `SO-${4410 + i}`,
  weight: 20 + i * 17,
  to: ["Grenoble", "Lyon", "Annecy"][i % 3],
  express: i % 4 === 0,
}));

export default function LongAndEmpty() {
  return (
    <div style={{ display: "grid", gap: 16, width: "100%", maxWidth: 520 }}>
      <JsonView label="Input · 12 items" value={orders} maxHeight={220} />
      <JsonView label="Output" value={undefined} empty="Not run yet" />
    </div>
  );
}
API → Props
PropTypeDefaultDescription
valueunknown—Any JSON value; undefined shows empty.
labelstring—Above it, and its name.
maxHeightnumber | "none"320Then it scrolls.
copyablebooleantrueThe copy button.
classNamestring—Extra classes.