renderSchema
Render a SchemaNode tree as compact, human-readable text.
Signature
function renderSchema(node: SchemaNode, options?: RenderOptions): string;Options
| Option | Type | Default | Description |
|---|---|---|---|
showStringLengths | boolean | false | Show 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.
Try it: Inline Object (< 80 chars)
Small nested objects stay on one line: meta: {page: number, total: number}.
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.
Try it: Nested Inline
When inner objects are small enough, they nest inline: product: {details: {manufacturer: string, model: string}, price: number}.
Try it: Array of Objects (Inline)
Array items that fit under 120 chars render inline.
Try it: Array of Objects (Multi-line)
When array items have many keys (> 120 chars inline), they expand with indented keys inside { }.
Try it: Optional Keys
Keys that appear in only some array elements are tagged (optional). Here name is in 1 of 2 elements.
Try it: Varying Array Sizes
When nested arrays have different lengths across elements, the count is replaced with array(varying sizes).
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.
Try it: String Lengths
Toggle showStringLengths to see character counts on string fields, e.g. string(5).
Try it: Empty Containers
Empty arrays show empty, empty objects show {}.
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: numberFormatting rules
| Condition | Format | Example |
|---|---|---|
| Root object | Keys expanded, one per line | name: string |
| Nested object < 80 chars | Inline | meta: {page: number, total: number} |
| Nested object >= 80 chars | Dot-path expansion | product.name: string |
| Array items (object) < 120 chars | Inline | array(5) of {id: number, name: string} |
| Array items (object) >= 120 chars | Multi-line with indentation | array(1) of {\n id: number\n ...} |
| Array items (non-object) | Always inline | array(3) of string |
| Optional keys | Tagged | (optional) string |
| Varying array sizes | Count replaced | array(varying sizes) of string |
| Union types | Pipe-separated with counts | {id: number}(×3) | string |
| Empty array | Tagged | array(0) empty |
| Empty object | Braces | {} |