JSON sample · schema · types · SQL · validation
One JSON sample, four contracts
Paste a real API response, webhook body or config file. SchemaForge writes the JSON Schema, the TypeScript types, the Zod schema and the CREATE TABLE statements from it, then validates any payload against that schema with the exact path and value that failed. No account, no upload, no cookies.
- 100% in the tab
- No upload
- No account
- No cookies
- Works offline after load
In short
SchemaForge is a free browser tool that reads a JSON sample and writes four things from it: a JSON Schema Draft 2020-12 document, TypeScript types, a Zod schema and PostgreSQL or SQLite CREATE TABLE statements. It also validates a JSON payload against a JSON Schema and reports every failure with its path, the expected value and the actual one. Parsing, inference and generation all run locally in the tab: nothing is uploaded, no account is needed, and no cookie or local storage is written.
From a JSON sample to a schema and code
100% localPaste one real response, event or document. Keys stay in the order you wrote them, and every key you include becomes a required property.
Output
Every line above comes from the sample in this tab. Nothing is uploaded and nothing is stored, so a reload clears it.
Validate a payload against a schema
100% localPaste a JSON Schema on the left and the payload on the right, or load a sample and switch its payload between valid and broken.
Supported keywords: type, required, properties, additionalProperties, items, minItems, maxItems, minimum, maximum, minLength, maxLength, pattern, enum, format, anyOf.
How it works
01 / 03- 01
Paste the sample
One real response is enough. Keys keep their order, integers stay integers, and a string that looks like a date, an email, a UUID or a URL gets the matching format hint.
- 02
Pick the output
The same schema is rendered as JSON Schema, TypeScript, Zod or SQL. Switch between named and inline types, interface or type alias, PostgreSQL or SQLite, and copy or download the result.
- 03
Validate against it
Load the schema into the validator and try a payload. A failure names the path, the keyword and both values, so a wrong field is a line you can fix rather than a message you have to interpret.
Guide
JSON / schema / SQLWhat one JSON sample can and cannot tell you
A sample is evidence, not a specification. Every key that appears becomes a property, every key that appears becomes required, and every value fixes a type. That is exactly what you want for a response you have just captured, and exactly where a generated schema can mislead you if you stop reading at the first output.
The usual traps are small and predictable. An optional field that happened to be present becomes required. A field that was null in this one response becomes a null-only type. An array with a single element gives the schema for that element and nothing about the others. A price that was 12.0 reads as a number, and a price that was 12 reads as an integer, so a currency amount inferred from one sample may still be too narrow for the next.
SchemaForge makes those decisions visible rather than clever. Types are inferred from the value in front of it, arrays merge what they contain, and the output is a starting point you edit: remove a name from required, widen an integer to a number, or add minimum and maxLength once you know the rule behind the field. A schema that says what the server actually accepts is better than one that merely describes one happy response.
How the inference works
Inference walks the JSON in document order and keeps the key order it finds, because a schema is easier to review when it looks like the payload it came from.
Objects become type: object with a properties map, a required list holding every key present in the sample, and additionalProperties: false. That last default is opinionated: it catches a renamed or misspelled field at the edge of the system, which is the failure a schema usually gets added for. If the payload legitimately carries extra keys, delete the line or set it to true.
Arrays merge the schemas of their elements. A list of objects becomes an items schema whose properties are the union of all element keys, and whose required list keeps only the keys present in every element. A list of one string and one number becomes anyOf with both branches, and a list of integers and numbers collapses to number, because an integer is a number with a narrower rule. An empty array has nothing to merge, so items is left as {} and accepts anything until you fill it in.
Strings get a format hint when the value matches a shape precisely enough to be useful: date-time for an ISO 8601 timestamp with a zone, date for a calendar date, email, uuid and uri for the obvious cases. The hint is a claim about the value that was there, not a proof about the next one, and it is a keyword most validators treat as an assertion, so check that your own validator does what you expect with it.
Numbers and booleans keep the JavaScript distinction: a value without a fractional part is integer, anything else is number. Null becomes type: null; if a field is sometimes a string and sometimes null, write type as a list of both, as the SaaS and GitHub samples do.
From schema to TypeScript
The TypeScript output is a direct translation. Objects become interfaces, arrays become T[], unions become A | B, and a property outside the required list gets a ?. Keys that are not valid identifiers are quoted, so "pull-request" stays legal.
With named types each nested object becomes its own declaration, named after the path that reached it: Root, RootData, RootDataObject, RootItems. That is what you want in an application where the same shape is reused across files and a compiler error should point at a name. With inline types the whole thing is one declaration, which is shorter to paste into a single file and harder to reuse. The interface and type alias switch changes only the declaration form; both accept the same object body.
Two habits keep generated types honest. Run tsc --strict over the file once, because a type that never compiles is a type nobody checked. And compare a type against a second sample of the same endpoint: if the second sample needs a field the type calls optional, the schema was too narrow, which is a fact about the first sample rather than a bug in the generator.
Zod, and where the runtime check belongs
The Zod output mirrors the same schema with z.object, z.array, z.union, .optional() for a property outside required, .nullable() for a null branch, and .email(), .uuid(), .url(), .datetime(), .date() for the format hints. The generated file ends with z.infer, so the TypeScript type and the runtime check come from one source and cannot drift apart.
Zod belongs at the boundary: the webhook handler, the queue consumer, the fetch wrapper. Parsing there turns a malformed payload into a failed promise with a field path instead of a undefined that surfaces three functions later. Where the schema came from a sample, tighten the permissive parts before you ship it, since z.string() from a sample cannot know that a currency code is three letters.
SQL: what a JSON document becomes
The DDL output maps each top-level property to a column. Strings become TEXT, with UUID, DATE and TIMESTAMPTZ for the format hints; integers become INTEGER, numbers NUMERIC, booleans BOOLEAN; nested objects and arrays are kept as JSONB in PostgreSQL and as JSON text in SQLite, because flattening an arbitrarily nested document into tables is a modelling decision that a generator should not make for you. A column outside the required list is nullable, and a column named id becomes the primary key.
SQLite has no boolean, timestamp or UUID type, so those three become INTEGER or TEXT and the DDL stays honest about the engine it targets. Names are converted to snake_case, and a name that collides with a reserved word is quoted. Before running the file, add the constraints a sample cannot reveal: unique keys, foreign keys, check constraints, and indexes on the columns you filter by.
What the validator checks
The validator implements the assertions that decide whether a payload is acceptable, and nothing else: type (including a list of types), required, properties, additionalProperties: false, items, minItems, maxItems, minimum, maximum, minLength, maxLength, pattern, enum, format and anyOf. Annotations such as title, description, examples and $comment are ignored, as the specification intends them to be.
Each failure is one line: the instance path such as $.data.object.amount_total, the keyword that failed, the expected value and the actual one. A type failure stops the walk down that branch, because reporting minLength on a number is noise. None of the checks rewrite or coerce the payload: "12" is not the number 12, and a timestamp without a zone is not a date-time.
Two limits are worth knowing. The validator is deliberately a subset, so a schema using oneOf, allOf, $ref, dependentRequired or if/then will be checked only on the keywords listed above, and a keyword it does not know cannot fail. And validation runs in this tab: it is a way to test a schema against real payloads while you write it, not a gate you can call from a server.
A short workflow that holds up
- Capture a real payload, not a hand-written example. A sample you typed yourself encodes what you believe, not what the server sends.
- Generate, then read the output for the traps: a required field that is really optional, a null-only type, a badge of
additionalProperties: falseon an object that legitimately grows. - Add the rules a sample cannot show:
minimum,maxLength,pattern,enum. Those are the checks that catch a bad value rather than a wrong shape. - Validate a known-bad payload before you trust the schema. A schema that accepts everything it is shown has not been tested.
- When the API changes, capture a new sample and diff the two schemas. A field that moved or changed type is a deploy you need to know about.
FAQ
9Is SchemaForge free, and do I need an account?
Does my JSON leave the browser?
Why is every key required in the generated schema?
Why is additionalProperties: false the default?
true or delete the line; a JSON Schema without the keyword allows extra properties.Can it read a JSON Schema back into TypeScript or Zod?
How do I validate a sample with several shapes in one array?
anyOf for mixed elements, and the validator checks each branch until one matches. If the payload should always match exactly one, write oneOf by hand; this validator reports unknown keywords as unchecked rather than pretending to enforce them.Which JSON Schema draft is generated?
$schema on the first line. The keywords used are the stable core that draft shares with earlier ones, so the output also runs on draft-07 validators in most cases, but the declaration is the honest one.Does the SQL output create several tables for nested objects?
JSONB column in PostgreSQL and a JSON text column in SQLite. That keeps the mapping inspectable; splitting a document into tables is a modelling choice that depends on how you query it, so it is left to you.