Valid JSON is not always valid business data. A shopping-cart request can have perfect punctuation while containing a negative quantity or omitting a required identifier. JSON Schema lets a team define rules that describe which JSON values are accepted by a particular contract.
\n

\n
Quick takeaway: This guide explains json schema through real-world examples, frequent errors and ways to verify your work. Use sample records rather than private client data when trying online tools.
Syntax validity versus a JSON Schema
Syntax validation asks whether the text follows JSON grammar; schema validation asks whether a parsed value meets defined constraints. A formatter might happily display {“quantity”:-5}, but a shopping API could reject a negative quantity. These are different layers of validation and should be tested separately. The example schema uses the published Draft 2020-12 dialect.
{
"$schema":"https://json-schema.org/draft/2020-12/schema",
"type":"object",
"properties":{
"sku":{"type":"string","minLength":1},
"quantity":{"type":"integer","minimum":1}
},
"required":["sku","quantity"],
"additionalProperties":false
}
This schema accepts an object with the two specified properties and rejects missing or unexpected properties. Strict additionalProperties settings are a design choice, not a universal rule.
Understand required and optional data
The required keyword lists property names that must exist on an object. A property omitted from required is usually optional even if it has a type definition under properties. Missing is not the same as null: a value can be required and still allow null when its type lists it as accepted.
{"type":"object","properties":{"nickname":{"type":["string","null"]}},"required":["nickname"]}
This instance must have a nickname key, but either a string or null may be provided. Clear contracts help clients distinguish unknown, absent, deliberately blank and not-applicable information.
Validate nested arrays
An API commonly receives a list of line items or records. Use type: array with an items schema to constrain each element. minItems can require a non-empty list. uniqueItems compares entire JSON values rather than deduplicating by a specific field such as SKU.
{
"type":"array",
"minItems":1,
"items":{
"type":"object",
"properties":{"id":{"type":"string"},"count":{"type":"integer","minimum":1}},
"required":["id","count"]
}
}
For a larger schema, shared definitions can reduce duplication. Test both good and deliberately malformed cases to check that your validator reports useful errors.
Use JSON Schema in API development
Start with the expected request or response shape and write down required fields and types. Create representative valid data and negative examples. Use a library compatible with the chosen draft to validate instances. Include these checks in automated API tests so a change to backend data does not silently break mobile or web clients.Schema tools cannot automatically prove that a customer’s address is deliverable or an item is in stock. Those are application and operational rules that live beyond structural JSON checks.
International considerations for APIs
For distributed projects serving the USA, UK, Canada, Australia and China, specify currency using ISO-style codes, store timestamps in a consistent format and allow Unicode in string fields. Do not constrain names to ASCII just because a simple test fixture only contains English letters.Treat personally identifiable data with appropriate privacy safeguards and permission checks. Validation is not a substitute for authentication, authorization or secure storage.
Frequently asked questions
Does a JSON formatter validate schemas? No, formatting alone checks presentation, not a full schema. What does type: integer mean? It accepts numbers with integer values according to the schema semantics. Does required imply non-null? No. Is additionalProperties false mandatory? No, it can improve strictness but reduce extensibility. Can schemas version APIs? They can document and test evolving contracts, but version strategy requires broader planning.
Practical checklist before using this in production
- Confirm that the source, file extension, expected type and encoding match your data contract.
- Test a typical valid example and at least one deliberately invalid example.
- Check empty values, missing fields, Unicode input and unusual numbers rather than relying only on the easiest sample.
- Keep secrets and personal data out of public web-based tools unless your organization has approved the handling.
- Document version, timezone and currency assumptions for projects in the USA, UK, Canada, Australia or China where they are relevant.
These practices make the examples easier to adapt internationally without assuming that a local service is available in every region.
Relevant free tools on Perkability Rewards
Try the directly linked utilities, not a new landing page. The site also has an existing JSON errors guide and a JSON arrays tutorial.
- JSON Formatter: practise using non-sensitive sample data relevant to this topic.
- URL Encoder & Decoder: practise using non-sensitive sample data relevant to this topic.
Authoritative technical references:
Disclosure: This educational article includes a third-party Adsterra 160×600 banner and social bar. Their display depends on the visitor’s browser and advertising-network settings. The article does not make promises about Google ranking or location-specific availability.

4 Responses