Skip to content

JSON Schema

Edit the JSON Schema on the left and apply it: the form regenerates on the right — no compiled model required. Alongside the standard keywords ($ref, allOf, if/then, dependentRequired, enum, format…), Borm reads a small set of x- extensions for the UI intent JSON Schema cannot express: widgets, layout, conditional visibility and wizard steps. Export (round-trip) writes the whole thing back out, conditions and steps included.

Each example shows a different part of the format. Conditional: a $ref into $defs, dependentRequired (a card number makes the billing reference required), fields shown, required and cleared by x-visibleWhen/x-requiredWhen/x-clearOnHide, and a two-column grid. Wizard: x-steps, a step shown only for business accounts, and if/then. Subforms: a oneOf told apart by a const becomes a choice with each branch's own fields, dependentSchemas asks for a VAT number once a company is given, and allOf merges a shared contact shape. Expressions: totals, rules and conditions written as text, in tabs. Break the document and Apply says why rather than throwing; Export shows what Borm makes of it.
Schema

definition.Validate() - the schema's own checks

No problems found.
The form it becomes
Event registration

View source
@page "/json-schema"

<textarea @bind="_json" @bind:event="oninput"></textarea>
<button @onclick="Rebuild">Apply schema</button>
<button @onclick="ExportRoundTrip">Export (round-trip)</button>

@if (_schema is not null)
{
    <BormView @key="_version" Definition="_schema" Data="_data"
              OnValidSubmit="HandleSubmit" SubmitText="Submit" ShowErrorSummary="true" />
}

@code {
    private BormDefinition? _schema;
    private IReadOnlyList<BormSchemaDiagnostic> _diagnostics = [];
    private Dictionary<string, object?> _data = new();
    private int _version;
    private string? _error;

    private void Rebuild()
    {
        // TryImport reports a malformed document instead of throwing — the shape you want behind
        // a "paste your schema here" editor.
        if (BormJsonSchemaImporter.TryImport(_json, out var schema, out _error))
        {
            _schema = schema;
            // The schema's own checks - duplicate names, conditions pointing nowhere, cycles - as a development aid.
            _diagnostics = schema.Validate();
            _data = new Dictionary<string, object?>();
            _version++;
        }
    }

    private void ExportRoundTrip()
    {
        if (_schema is null) return;
        // Conditions, wizard steps, layout and widget choices all survive the round-trip.
        _json = BormJsonSchemaExporter.Export(_schema);
    }
}

What the importer reads

Drafts 07 to 2020-12: type (nullable unions such as ["string","null"] too), properties, required, enum, const, format (date, time, date-time, color and password choose the control; email, uri and uuid add the matching rule too), default, examples (suggestions), readOnly, minimum/maximum and their exclusive forms, multipleOf, minLength/maxLength, pattern, items, minItems/maxItems, uniqueItems, $ref into $defs/definitions (recursion followed one level), allOf (merged, the stricter bound winning), if/then/else, dependentRequired, dependentSchemas and draft-07's dependencies, and oneOf/anyOf - a null union, a list of titled const branches (a labelled select), or object branches told apart by a const or OpenAPI's discriminator (subforms). An array of an enum with uniqueItems is a multi-select.

TryImport is the call for a document a user typed: besides malformed JSON, it refuses one that is not a schema, an expression that does not parse (naming the field), and one past the budgets no real form comes near - 10,000 fields, 32 levels of nesting - since a few hundred bytes of $refs can describe millions of fields.

The x- extensions

UI intent JSON Schema has no word for travels in x- keywords, and all of it survives an export and a second import. What is written in C# - a Must(predicate), an OptionsFrom provider, an OnChange handler, an uploader - has no JSON form and is left out of the export rather than approximated; what is written as an expression is exported as the text it was written as.

KeywordMeans
x-widgetThe control: select, radio, textarea, combobox, multiselect, tags, range, switch, month, week, markdown, signature, static, hidden, …
enumNames, x-enumGroups, x-enumDisabledOption labels, the <optgroup> each belongs to, and choices that cannot be picked.
x-allowCustom, x-enumA combobox that also takes answers on no list; its suggestions.
x-visibleWhen, x-requiredWhen, x-disabledWhen, x-readOnlyWhen, x-clearOnHideConditions - an expression string, {"field", "op", "value"}, or {"all": […]} / {"any": […]} of either.
x-computed, x-rules, x-revalidateOnA value derived from others, rules written as expressions (with a severity), and the other half of a cross-field rule.
x-steps, x-stepLayoutSteps (id, title, fields, visibleWhen) and how they show: wizard, tabs, accordion, sections.
x-columns, x-colSpan, x-order, x-group, x-pageSizeThe grid, the order, a <fieldset> and a long list shown a page at a time.
x-placeholder, x-prefix, x-suffix, x-showLabel, x-characterCount, x-autocomplete, x-inputMode, x-autofocusPresentation and the browser's hints.
x-updateOn, x-debounce, x-stepWhen the value is written back, and the control's granularity.
x-mask, x-maskStoresRawA fixed shape such as (000) 000-0000, and whether the model keeps only the slots.
x-accept, x-multiple, x-maxFileSizeFile upload limits.
x-sensitive, x-versionKept out of drafts; the form's version, recorded in each draft.
x-i18n, x-translationsA field's translation key, and the form's texts per language.
x-renderer, x-attributes, x-inputAttributesA custom renderer's key, renderer hints, and extra HTML attributes.
An unhandled error has occurred. Reload 🗙