Q:What is the difference between JSON Schema and JSON validation?
JSON validation is the process of checking JSON against rules. JSON Schema is a standardized vocabulary for describing many structural rules, and a schema validator applies those rules to a JSON instance.
Q:Is JSON Schema the same as JSON validation?
No. JSON Schema defines constraints, while validation is the process of checking a JSON instance against those constraints. Validation can also refer to syntax or application-level checks.
Q:What is JSON Schema used for?
JSON Schema is used to describe expected JSON structure, data types, required properties, allowed values, array constraints, string constraints, and other rules.
Q:What is JSON validation?
JSON validation is the act of checking JSON data against rules. Depending on the context, it can mean syntax validation, JSON Schema validation, or application-specific validation.
Q:What is the difference between JSON syntax validation and schema validation?
Syntax validation checks whether the text follows JSON grammar. Schema validation checks whether a successfully parsed JSON instance satisfies a defined structural schema.
Q:Can valid JSON fail JSON Schema validation?
Yes. Valid JSON can still fail because a required property is missing, a value has the wrong type, an enum value is not allowed, or another schema constraint is violated.
Q:Does JSON Schema validate JSON syntax?
Schema validation normally operates on a parsed JSON instance. Malformed JSON must first be rejected or corrected at the parsing stage.
Q:Can JSON Schema check required fields?
Yes. The required keyword can specify which property names must be present in an object.
Q:Can JSON Schema validate data types?
Yes. JSON Schema can constrain values using types such as object, array, string, number, integer, boolean, and null.
Q:Can JSON Schema validate arrays?
Yes. JSON Schema can describe array item types and can also apply constraints such as minimum and maximum item counts or uniqueness where appropriate.
Q:Can JSON Schema validate nested objects?
Yes. Nested properties can have their own schemas, allowing validation to continue through deeply structured JSON.
Q:Can JSON Schema restrict allowed values?
Yes. The enum keyword can restrict a value to a defined set, while other schema constructs can express more complex alternatives.
Q:Can JSON Schema validate API requests?
Yes. A schema can describe an API request body and a compatible validator can check incoming data against that structure.
Q:Can JSON Schema validate API responses?
Yes. Response data can be validated against a schema to detect responses that do not conform to the documented contract.
Q:Should I validate JSON before parsing it?
Parsing is itself the normal first step for raw JSON text. If parsing fails, schema validation cannot meaningfully evaluate the JSON instance.
Q:What happens when JSON parsing fails?
The text cannot be converted into a JSON data structure, so schema-level validation cannot proceed until the malformed input is corrected or rejected.
Q:What is the difference between JSON Schema and TypeScript types?
TypeScript types primarily provide compile-time type information. JSON Schema provides a language-independent description that can be evaluated at runtime by a compatible validator.
Q:Does a TypeScript interface validate API responses?
Not by itself. A TypeScript interface does not automatically perform runtime validation on data received from an external API.
Q:What is the difference between JSON Schema and OpenAPI?
JSON Schema focuses on describing and validating JSON instances. OpenAPI describes HTTP APIs more broadly, including operations, parameters, requests, responses, authentication, and schemas.
Q:Is JSON Schema good for API contracts?
JSON Schema can provide a machine-readable description of API payload structure and constraints. Whether it is sufficient for an entire API contract depends on the API documentation and tooling requirements.
Q:Can JSON Schema enforce business rules?
It can express many structural constraints, but application-specific business rules often require additional program logic, especially when they depend on database state or external systems.
Q:What is manual JSON validation?
Manual validation uses application code to inspect fields and values directly rather than relying solely on a declarative schema.
Q:Should I use JSON Schema or manual validation?
They can complement each other. JSON Schema is useful for reusable structural constraints, while application code can handle domain rules that depend on runtime state or business logic.
Q:What is schema validation error?
It is an error reported when a JSON instance does not satisfy one or more schema constraints, such as a required property, data type, enum, array, or string constraint.
Q:What is the difference between optional and nullable JSON properties?
An optional property may be absent. A nullable property may be present with null when the schema allows null. A property can be optional, nullable, both, or neither.
Q:Does JSON Schema allow unknown properties?
The schema can control how additional properties are handled. The exact behavior depends on the schema keywords and dialect used.
Q:Can JSON Schema validate generated JSON?
Yes. Generated JSON can be parsed and then checked against a schema before being passed to another system.
Q:Can JSON Schema be used in CI?
Yes. Schema validation can be included in automated tests and CI pipelines for fixtures, API contracts, generated data, configuration files, and other structured JSON.
Q:Why is my JSON valid but rejected by the API?
The JSON may be syntactically valid but fail the API's schema, field requirements, data types, allowed values, authentication requirements, or business rules.
Q:What should I validate first: syntax or schema?
For raw JSON text, check syntax first by parsing it. Once you have a valid JSON instance, apply schema validation and then any additional application-level rules.
Q:Can a JSON formatter replace JSON validation?
No. Formatting makes valid JSON easier to read, while validation determines whether JSON meets syntax or structural requirements.