Quick summary
Learn JSON Schema step by step with practical examples for object types, required fields, arrays, enums, nested data and API validation. This guide gives you a clear, practical explanation before you use the related online tool.
JSON Schema in plain language
JSON Schema is a vocabulary for describing the expected shape and constraints of JSON data. A schema can say that a value must be an object, that particular properties should be strings or numbers, that some fields are required and that arrays must contain a particular kind of item.
Start with type and properties
A beginner schema for a customer object normally starts with type: object and a properties map. Each property gets its own rules, such as type: string for name and type: integer for age. Defining a property does not automatically make it required.
Required fields are separate
Use the required array to list property names that must be present. This distinction is important: properties describes allowed or validated fields, while required controls presence. Applications should also decide how they want to handle null values because a missing property and a property whose value is null are different cases.
Strings, numbers and common constraints
Schemas can add constraints beyond basic types: minLength and maxLength for strings, pattern for text formats, minimum and maximum for numbers, and enum for a fixed set of values. Add constraints because the business contract requires them, not simply because the schema language supports them.
Arrays and nested objects
For an array such as orders, set type to array and describe each element with items. If each order is an object, items can contain its own properties and required rules. Nested schemas should mirror the real payload structure and should be tested with both valid and intentionally invalid examples.
A practical API example
Imagine an API request with customerId, email and roles. The schema can require customerId and email, validate them as strings, and define roles as an array of strings. This creates a machine-readable contract that can be reused in tests, documentation or validation layers, depending on the tooling.
Generating a schema from sample JSON
A generator can infer a useful starter schema from a representative sample, but inference cannot know every business rule. A sample value of 42 may suggest an integer, but it cannot tell the generator whether the allowed range is 1–100. Review generated schemas before treating them as contracts.
Validation workflow and common mistakes
Validate several realistic payloads, including missing required fields, unexpected types, empty arrays and boundary values. Watch for over-restrictive schemas based on one sample and under-restrictive schemas that omit important business constraints. Keep schema versions aligned with the applications that consume them.
Continue with a free tool
Related FormatForge tools
JSON Schema Generator
Generate a JSON Schema from sample JSON for API validation and documentation.
Open tool →JSON Studio
Format, validate, view, compare, split, merge and analyze JSON in one professional workspace.
Open tool →JSONPath Explorer
Test JSONPath expressions against JSON data and inspect the matching values.
Open tool →Explore the complete workflow
Continue from this guide to the broader category or curated collection to find related tools and supporting workflows.
Frequently asked questions
What is JSON Schema used for?
It describes and validates the expected structure and constraints of JSON data.
Does listing a property make it required?
No. Required property names are normally listed separately in the schema’s required array.
Can JSON Schema validate arrays?
Yes. A schema can define an array and specify rules for its items.
Can a schema be generated from sample JSON?
Yes, but generated output is a starting point because a sample cannot reveal every business rule.
Is JSON Schema useful for APIs?
Yes. It can provide a machine-readable contract for request or response structures and can support validation, testing and documentation workflows.
Keep learning
Related guides
Developer
JWT Explained for Developers: Structure, Claims, Signatures and Validation
Understand JSON Web Tokens, header-payload-signature structure, claims, signature verification, expiration and common JWT security mistakes.
Developer
Base64 Encoding Explained: Text, Images, Data URLs and Decoding
Understand what Base64 encoding does, why encoded data grows in size, how images and Data URLs use Base64, and when to encode or decode it.
Developer
Cron Expression Guide with Examples: Minutes, Hours, Days and Scheduling
Learn cron expression fields with practical examples for hourly, daily, weekly and monthly schedules, plus common portability and timezone mistakes.
Developer
Regex Tester Guide for Beginners
Learn how regex patterns work and how to test them safely.