Skip to content

renderSchema

Render a SchemaNode tree as compact, human-readable text.

Signature

typescript
function renderSchema(node: SchemaNode, options?: RenderOptions): string;

Options

OptionTypeDefaultDescription
showStringLengthsbooleanfalseShow character counts, e.g. string(21) instead of string.

How rendering works

The renderer walks the SchemaNode tree and makes formatting decisions at each level:

  • Primitives — rendered as their type name: string, number, boolean, null
  • Objects — rendered inline {key: type} if under 80 chars, otherwise expanded with dot-paths
  • Arrays — show element count and item type: array(25) of {id: number}
  • Unions — show all variants with | and counts: {id: number}(×3) | string

Try it: Primitives

All four primitive types rendered on separate lines.

renderSchema()
mode
depth 10
Input
Output

Try it: Inline Object (< 80 chars)

Small nested objects stay on one line: meta: {page: number, total: number}.

renderSchema()
mode
depth 10
Input
Output

Try it: Dot-Path Expansion (> 80 chars)

When a nested object is too wide for inline, keys are expanded with dot-joined paths like product.name: string.

renderSchema()
mode
depth 10
Input
Output

Try it: Nested Inline

When inner objects are small enough, they nest inline: product: {details: {manufacturer: string, model: string}, price: number}.

renderSchema()
mode
depth 10
Input
Output

Try it: Array of Objects (Inline)

Array items that fit under 120 chars render inline.

renderSchema()
mode
depth 10
Input
Output

Try it: Array of Objects (Multi-line)

When array items have many keys (> 120 chars inline), they expand with indented keys inside { }.

renderSchema()
mode
depth 10
Input
Output

Try it: Optional Keys

Keys that appear in only some array elements are tagged (optional). Here name is in 1 of 2 elements.

renderSchema()
mode
depth 10
Input
Output

Try it: Varying Array Sizes

When nested arrays have different lengths across elements, the count is replaced with array(varying sizes).

renderSchema()
mode
depth 10
Input
Output

Try it: Union with Variant Counts

Mixed-type arrays show each type with |. Types appearing multiple times show a count like (×3). Switch to exhaustive mode to catch all types.

renderSchema()
mode
depth 10
Input
Output

Try it: String Lengths

Toggle showStringLengths to see character counts on string fields, e.g. string(5).

renderSchema()
mode
depth 10
Input
Output

Try it: Empty Containers

Empty arrays show empty, empty objects show {}.

renderSchema()
mode
depth 10
Input
Output

Output Format

The output is not standard JSON Schema. It's a compact text format designed for minimal tokens:

data.users: array(25) of {id: number, name: string, email: string}
meta.page: number
meta.total: number

Formatting rules

ConditionFormatExample
Root objectKeys expanded, one per linename: string
Nested object < 80 charsInlinemeta: {page: number, total: number}
Nested object >= 80 charsDot-path expansionproduct.name: string
Array items (object) < 120 charsInlinearray(5) of {id: number, name: string}
Array items (object) >= 120 charsMulti-line with indentationarray(1) of {\n id: number\n ...}
Array items (non-object)Always inlinearray(3) of string
Optional keysTagged(optional) string
Varying array sizesCount replacedarray(varying sizes) of string
Union typesPipe-separated with counts{id: number}(×3) | string
Empty arrayTaggedarray(0) empty
Empty objectBraces{}