A JSON sample is not a schema

CodeMoment · Updated 2026-10-31

A JSON sample shows one shape that happened to occur. A schema is a rule for later documents. Generating the second from the first is useful, and it is not the same job as checking a document, or as writing TypeScript.

Give the generator one object whose fields are a string name and a boolean active flag. Draft 2020-12 output lists those properties, and both are required, because both appeared. A field that never appears is not invented. If some records have a nickname and some do not, put the objects in one array. The generator merges them, and a field missing from some items is not required. The sample values themselves are copied into the schema only when you turn examples on. Otherwise you get the shape, not a second copy of the data.

Integers past 9007199254740991, which is 2^53 - 1, stay integers in that schema. The digits are not rounded. The JSON Schema page does this locally and does not upload the sample. It does not then check another document. A field that was not in the sample is absent until you edit the schema.

Validation is the other direction. You paste JSON and a schema. A schema with no $schema is read as draft 2020-12. Draft-07 is selected only by its own $schema URL. The difference is not cosmetic: exclusiveMinimum is a boolean in draft-07 and a number in draft 2020-12, so the same keyword accepts different documents. Errors name a path and a rule, and they do not echo the JSON value. A $ref that points at another website is not fetched. The referenced schema has to be in the document you pasted. Integers beyond 2^53 - 1 are not exact in JavaScript here. The JSON Schema Validator warns and applies numeric rules to the rounded value. The formatter can keep those digits. This checker cannot, because the rules run in ordinary JavaScript numbers.

JSON to TypeScript is a third reading of the same sample. Nested objects become nested types, null stays in the type, and a field missing from some array items becomes optional. A number past the safe integer range is still typed as number, with a comment. TypeScript will not grow a bigint from digits the sample happened to contain, unless those digits were stored as a string. The type describes the sample you pasted. A string in that sample may be a number in production.

Use the generator when you want a draft to edit. Use the validator when you already have a schema and a document. Use the TypeScript output when the next step is a type in a program. None of the three uploads what you paste.