How can I catch new posts?
Bookmark this blog and watch the homepage and tools hub—we surface new guides there. No account or mailing list is required to read articles.
Understand the difference between JSON syntax validation, lint rules, and JSON Schema contracts through one API example—and learn when to use each layer together.
A JSON document can parse successfully and still be rejected by an API. A validator can call it valid while a linter continues to report issues. These results are not contradictory: the tools answer different questions.
A JSON Validator checks whether text is legal JSON. A JSON Linter checks quality and consistency rules. JSON Schema describes the structure and constraints that data must satisfy. They complement one another rather than compete.
| Tool | Core question | Typical result |
|---|---|---|
| JSON Validator | Is this text valid JSON? | Valid, or a syntax error location |
| JSON Linter | Does this JSON follow quality and team rules? | Warnings and rule violations |
| JSON Schema | What data shape does the application accept? | A machine-readable data contract |
> A practical order is: validate syntax, run lint rules, then validate the data against a JSON Schema.
The term “JSON Validator” is used for two different tools:
JSON.parse or an equivalent parser.Json Work's JSON Validator is primarily a syntax validator. In the official JSON Schema documentation, a validator usually means the second kind: a tool that takes a Schema and an Instance and returns a validation result.
When documenting a system, say “syntax validator” or “schema validator” explicitly. Otherwise, two teams can use the same word for different quality gates.
JSON has a defined grammar. RFC 8259 specifies objects, arrays, strings, numbers, booleans, and null. A syntax validator checks characters and structure against those rules.
This is invalid because the properties are missing a comma:
{
"id": 101
"name": "Alice"
}A syntax validator can catch problems such as:
undefined, NaN, and InfinityAfter fixing the comma, the following document is valid JSON:
{
"id": "one hundred",
"email": "not-an-email",
"active": "yes"
}It may be useless to your application, but every token is legal. A syntax validator does not know that id should be an integer or active should be boolean. It answers only: Is this legal JSON text?
Use the JSON Validator to locate syntax errors. If the input is only JSON-like, use JSON Repair to produce a candidate fix, then review the change rather than assuming the repaired meaning is correct.
Linting is rule-based static analysis. Unlike JSON grammar, lint rules are generally not one universal standard. A tool or team chooses rules that reflect maintainability, style, and risk.
Consider this valid JSON:
{
"user_id": 101,
"userName": "Alice",
"isActive": "true"
}A linter might report:
snake_case and camelCase property namesThese findings are not automatically data errors. The upstream contract may require "true" as a string, and neither naming convention is universally superior. A linter makes implicit conventions visible and helps a team remain consistent.
The JSON Linter is therefore useful for answering questions about naming, consistency, maintainability, and suspicious structures. Without a contract, it can suggest that isActive looks unusual, but it cannot prove the value is wrong.
JSON Schema is a standardized vocabulary for describing and constraining JSON documents. It can express types, required properties, nested objects, array items, numeric limits, string lengths, enums, and combined conditions. The JSON Schema project highlights validation, interoperable exchange, and documentation as core use cases.
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
"properties": {
"id": { "type": "integer" },
"name": { "type": "string", "minLength": 1 },
"email": { "type": "string", "format": "email" },
"active": { "type": "boolean" }
},
"required": ["id", "name", "email"],
"additionalProperties": false
}This contract states that id is an integer, name is a non-empty string, email is required, and undeclared properties are not accepted.
jsonschema applies the Schema to an actual JSON Instance. The official step-by-step guide uses the same distinction.Implementation options matter. For example, format may act as an annotation by default rather than a mandatory assertion, depending on the validator and configuration. The official format documentation calls out this behavior. Production systems should agree on a draft, validator, and options.
You can use the JSON Schema Generator to infer a starting schema from representative samples. Then review required fields and add ranges, lengths, patterns, enums, and additionalProperties rules. Inference cannot invent business knowledge that is absent from the samples.
Suppose an endpoint receives:
{
"id": "101",
"name": "Alice",
"email": "alice@example.com",
"active": "true"
}id and active look like values that might use numeric and boolean types. The linter can flag them for review but cannot establish the application's intent.id must be an integer and active must be boolean. This is a contract failure, not a syntax failure.Valid syntax does not imply consistent style or a valid business contract.
| Capability | JSON Validator | JSON Linter | JSON Schema |
|---|---|---|---|
| Check JSON syntax | Yes | Usually requires valid syntax first | The Schema must itself be valid JSON |
| Enforce property types | No | Can suggest suspicious types | Yes |
| Enforce required properties | No | Not reliably without a contract | Yes |
| Enforce naming style | No | Yes | Not its primary purpose |
| Enforce numeric limits | No | May warn | Yes, with keywords such as minimum |
| Standardized rules | JSON grammar is standardized | Depends on tool and team | Drafts and vocabularies are standardized |
| Best result type | Syntax error | Warning or rule violation | Contract pass or failure |
| Suitable for API contracts | Not alone | Not alone | Yes |
For APIs, configuration, and data imports, use four distinct gates:
JSON Schema does not replace every business check. Rules such as “end time must be later than start time” or “this user may access this project” often belong in application logic. Schema success should not be treated as proof that a business operation is safe.
In CI, each gate should report a different kind of failure. Syntax errors should stop processing immediately. Teams can decide whether lint warnings block a change. Schema failures normally stop incompatible data from entering downstream systems. Business failures need domain-specific messages.
This minimal example uses only type and required so that format plugins do not distract from the flow.
import Ajv from "ajv";
const schema = {
type: "object",
properties: {
id: { type: "integer" },
name: { type: "string" },
active: { type: "boolean" }
},
required: ["id", "name"],
additionalProperties: false
};
const data = { id: "101", name: "Alice", active: true };
const ajv = new Ajv({ allErrors: true });
const validate = ajv.compile(schema);
if (!validate(data)) {
console.log(validate.errors);
}Ajv reports that id does not match integer. Its getting-started guide recommends compiling a schema once and reusing the validation function.
The example assumes data is already a JavaScript value. If input arrives as raw network text, parsing still comes first. Keeping syntax errors separate from schema errors produces much clearer feedback.
A syntax validator proves only that the text can be parsed. A schema validator proves only that data satisfies the supplied schema. Neither proves that the schema covers every business requirement.
Lint rules should support an explicit team convention. If a rule does not fit a data source, adjust the rule or document an exception instead of changing meaning mechanically.
One sample cannot reveal every optional field, range, enum, or edge case. Use diverse samples and have someone who understands the domain review the result.
It does not. Schema describes and validates data; it does not add commas, repair quotes, or recover truncated content. Invalid syntax must be handled first.
The three tools protect different boundaries:
The reliable approach is to use them in sequence. Start with the JSON Validator, inspect quality with the JSON Linter, and build a maintainable contract with the JSON Schema Generator. Each tool can run locally in your browser on JSON Work.
Dedicated to providing developers with the best JSON processing tools
More posts coming soon...
Back to BlogFollowing the blog, topics we cover, and how to suggest guides.
Bookmark this blog and watch the homepage and tools hub—we surface new guides there. No account or mailing list is required to read articles.
JSON validation, formatting, conversion, debugging workflows, and JSON Work releases—mapped to what the free on-site tools can do locally in your browser.
Yes. Reach out via the About page or GitHub; we prioritize guides tied to real integration and debugging scenarios.