Data Display

SchemaView

Read-only view of a JSON Schema: one row per field with its label, a coloured type mark, a required dot, the description and facts, nested fields folding.

import { SchemaView } from '@lostgradient/cinder';
schemajson-schemaread-onlydata-display
01

Overview

Reference usage

A read-only view of a JSON Schema as one aligned grid with the columns Field, Type and Description, on the fill a Card has, with hairlines between rows and no vertical rules. Every field is a row: its label, a small red dot after it when the field is required, a type mark (a short word on a light wash of its kind's hue: text green, number blue, yes or no amber, object violet, list teal, choice pink, any grey), then the first paragraph of its description, and under it the quiet facts about the value: the values it allows, its default, its format and its limits. Nested objects and the objects a list holds are indented under their field, which has a fold control that hides and shows them. The raw schema document sits behind a JSON schema disclosure, so the schema is never dumped as raw JSON.

How to read it, and what feeds it:

  • required first: the top-level required fields come first, then a single hairline, then the optional ones, with no group headers. Nested rows keep the schema's order and carry their own dots. The raw document keeps the file's order.
  • type marks and facts: the mark names the kind of value, and the facts say the rest in words: Whole number for an integer, Format: date and time, Holds text for a list of plain values, One of quick, thorough for an enum, Always 2 for a constant, Default thorough, Or none when null is allowed, limits such as 1 to 3 items, At least 1 character or 0 to 1, and Matches with a pattern. A field that holds a JSON schema (a format of json-schema, or a reference to the meta-schema) is any with the fact JSON schema.
  • choices: a oneOf or anyOf whose members are objects lists each branch's fields under the choice, labelled If email: Address. The branches are told apart by a property that is a constant in each one (kind: { const: 'email' }, with type, mode and variant tried first); that property is the choice's name for the branch and is not a row. Without one, a branch is named by its title, then by position (option 1). A branch's own required list gives its dots, so only the chosen branch's dots apply.
  • descriptions: a description is shown up to its first blank line. Anything after it is text written for a model, and a More link opens it in place (the link turns into Less). Write the line a person reads first, then a blank line, then the rest.
  • sentence-case labels: timeZone reads "Time zone", orderId "Order ID", through humanizeIdentifier in sentence case.
  • long values: a long field name truncates on one line with the full label as its tooltip, and the dot stays after it; a value with no spaces breaks anywhere inside its cell and never widens the grid.
  • phone width: when the view itself is narrower than 30rem the columns restack, with the label and type on one line, the type at the end, and the description and facts below it with More inline after it.
  • rows and the open document: layout="rows" drops the frame and the header row for a short input such as a tool's: each field is one row, its name flush with the text above, then the word Required, then its type in plain words, with the description and facts on the line below; nesting, folding and More work as in the grid. raw="beside" shows the raw document open in a JSON code block instead of behind the disclosure, beside the fields once the view is 38rem wide and under them when it is narrower; raw="none" leaves it out.

Local $refs into $defs or definitions are followed and allOf members are merged, including properties that more than one member declares. A reference that points back into the object being shown is not expanded again; its type reads, for example, node (recursive). The view lists at most 500 expanded fields, and an object it did not open past that shows the same note as one beyond maxDepth. A schema that is not an object with properties shows one Value row that names its type, and a schema with no fields shows one line, "This schema takes no fields, so there is nothing to fill in.", in a bordered box instead of an empty grid.

Use it wherever a schema is shown for reading: a workflow's input and output, a tool's input, the payload of a signal or an update, a question's answer. Use JsonSchemaEditor when the schema must be edited, and PayloadInspector when you are showing a value rather than the shape it must have.

Usage

svelte
<script lang="ts">
  import { SchemaView } from '@lostgradient/cinder';

  const refundInput = {
    $schema: 'https://json-schema.org/draft/2020-12/schema',
    type: 'object',
    required: ['orderId', 'customer'],
    properties: {
      orderId: { type: 'string', description: 'The order to refund.' },
      refundAmount: { type: 'number', description: 'Amount in cents. Defaults to the full order.' },
      customer: {
        type: 'object',
        required: ['email'],
        properties: {
          email: { type: 'string', description: 'Where the receipt is sent.' },
          loyaltyTier: { type: 'string' },
        },
      },
    },
  };
</script>

<SchemaView schema={refundInput} label="Refund input" />
Live preview

A choice of branches

Field
Type
Description
Notify
choice
Where the summary goes. One of email, slack, webhook
Notify › If email: Address
text
Who receives it.
Notify › If slack: Channel
text
The channel name, such as #refunds.
Notify › If webhook: URL
text
Called with the summary as JSON.
Notify › If webhook: Secret
text
Sent as a header. Never shown again.

A branch’s fields indent under their choice and read “If <choice>: <field>”. Only the chosen branch’s required dots apply.

02

When to use

Use when
  • Showing the shape of a workflow input or output, a tool input, or a signal or update payload without a raw JSON dump.
  • Telling the reader which fields are required and what type each one takes.
Avoid when
03

Examples

A choice of branches

A oneOf of objects lists each branch's fields under the choice, labelled "If <choice>: <field>". The caption says how to read the branches.

A schema with no fields

One line in a bordered box instead of an empty grid, with the raw document still one disclosure away.

Long names and unbroken values

A long field name truncates on one line and its full name is its tooltip, with the required dot after it. A value with no spaces breaks inside its cell and never widens the grid.

A nested schema

Required fields first with a red dot, nested objects indented, and the raw document behind the JSON schema disclosure.

A workflow file's schema

Field, Type and Description on one grid. Required fields come first, marked by a red dot after the label, with one hairline before the rest. Each type is a coloured mark with its facts (allowed values, default, format, limits) under the description, nested rows indent under their parent, and More opens the model-facing text in place.

04

Props

Props for schema-view
Name
Type
Default
Description
schema required unknown The JSON Schema to show, as a parsed object. Local $refs into $defs or definitions are followed and allOf members are merged. A schema that is not an object with properties shows one Value line naming its type.
label text 'Schema' Accessible name of the view, for example "Workflow input". It is the aria-label of the region, so name what the schema describes.
maxDepth number 8 How many levels of nested objects are expanded. Deeper objects show their line without their fields, and the raw document still holds them.
rawLabel text 'JSON schema' Label of the raw schema document: the disclosure's trigger, or the title over the code block.
emptyLabel text 'This schema takes no fields, so there is nothing to fill in.' Text shown, in a bordered box instead of an empty grid, when the schema declares no fields.
caption text A note shown as the last line of the frame, below the rows. Use it to say how to read the grid, for example how a choice's branches are labelled.
layout 'table' | 'rows' 'table' How the fields are drawn. table is the framed grid of Field, Type and Description under a header row. rows is one unframed row per field, its name flush with the text above it, then the word "Required", then its type as plain words, with its description and rules on the line below.
raw 'collapsed' | 'beside' | 'none' 'collapsed' Where the raw schema document is. collapsed puts it behind a closed disclosure after the fields. beside shows it open in a JSON code block: beside the fields when the view is at least 38rem wide, under them when it is narrower. none leaves it out.