Developer and Text Tools

How to Design Forms That Produce Valid JSON with JSON Schema

Learn how JSON Schema describes data, how forms map to schemas, how to model conditional fields with if/then/else, and how to validate JSON and YAML input.

Saizul Amin
Saizul Amin2 Nov 2026 · 3 min read
How to Design Forms That Produce Valid JSON with JSON Schema

How to Design Forms That Produce Valid JSON with JSON Schema

Many tools need input in an exact shape: a deployment config, an API request, an import file. When people write that JSON or YAML by hand, they forget required keys, put text where a number belongs and invent option values. A form that produces the data, combined with a JSON Schema that describes it, removes most of those errors. This guide explains how to design both, with the free JSON and YAML schema form builder.

JSON Schema in a nutshell

A JSON Schema is itself a JSON document that describes other JSON. For an object it lists properties with their types, a required array, and rules for each value: minLength and pattern for strings, minimum and maximum for numbers, enum for fixed choices, items for arrays and format for things like email addresses and dates. Validators such as Ajv check data against it; form libraries can render it as a form.

Map every field to a property

Each form field becomes one property. The field's key is the JSON property name, so choose stable, lowercase names like start_date that will not change when the label does. Labels and help texts become title and description, which also documents the data format for developers.

Pick types deliberately

Use integer rather than number for counts, a single choice for values from a fixed list, multiple choice for sets of options, and a list for free repeated values. Dates as strings with format date are easier to exchange than localised text. Group related fields such as an address into a nested object so the output has the same structure as your program expects.

Validation rules belong in the schema

Put every rule in the schema rather than only in the form: lengths, ranges, patterns and required fields. Then the same rules protect your API and your config loader, not just the browser. Patterns should be anchored with ^ and $ so that they describe the whole value.

Conditional fields with if, then and else

Real forms have questions that only matter after a certain answer: "Describe your role" only when the role is Other. JSON Schema expresses this with if, then and else. The if part tests another property, for example that role equals Other. The then part makes the extra field required, and the else part can forbid it so that data never contains answers to hidden questions. The form should mirror the same rule by hiding the field and removing its value.

JSON or YAML output

YAML is easier for people to read and is common in configuration files, while JSON is standard for APIs. They represent the same data, so one schema can validate both. Let users pick the format they need and keep the schema as the single source of truth.

Test with awkward data

Fill the form with edge cases: empty optional fields, the maximum length, zero, negative numbers, unusual characters in names. Check that the output still validates and that error messages explain what to fix in plain words.

Ship the form

A standalone HTML form with the schema embedded can be hosted anywhere, used offline or attached to an internal wiki. Connect its submit handler to your endpoint, and keep server-side validation with the same schema.

Limits

Browser validation can be bypassed, so always validate again on the server. JSON Schema is very expressive, and features such as references between schemas, polymorphic oneOf and dynamic properties are hard to represent as simple forms. Keep form schemas simple and use richer schemas behind the API where needed.

Completely freeNo cost, no sign-up
Files stay privateEverything runs in your browser
Easy in your languageAvailable in many languages