JSON Lint and Validation

Est. read: 6 minDeveloper
Curly brace icon representing validated JSON

Summary

Definition: JSON linting verifies that a document follows the JSON grammar.

Why it matters: Invalid JSON cannot be parsed and may break APIs or config loading.

Pitfall: Passing lint does not guarantee required keys, types, or formats.

Guide start

JSON linting is the fastest way to find syntax errors such as missing quotes or trailing commas.
Linters follow the official JSON grammar and report where parsing fails using line and column hints.

Key terms
JSON
A text format for structured data defined by a formal grammar.
Linting
A syntax check that verifies a document follows JSON rules.
Schema
A specification that defines required structure and constraints.
Validation
Checking data against syntax rules or a schema.
Line/column
The location where the JSON parser stopped reading.
Trailing comma
A comma after the last item, which JSON forbids.

How JSON lint works

A JSON linter runs a JSON parser against your document. The parser reads top to bottom and stops at the first invalid token.
Because the JSON standard does not define error reporting, messages vary by tool.

Common mix-up: Valid JSON means valid data. Syntax validity does not ensure required fields or types.

Linting vs validation

Lint vs Schema
Linting
Checks JSON syntax against the official grammar.
Schema
Checks structure, types, and required fields.

JSON syntax is formally defined by standards such as RFC 8259 and ECMA-404.

Common JSON lint errors

  • Trailing commas after the last item in an object or array.
  • Using single quotes instead of double quotes.
  • Missing quotes around object keys.
  • Unescaped line breaks inside strings.

Quick example

Example

This payload fails linting due to a trailing comma.

Broken JSON
{
  "name": "demo",
  "enabled": true,
}

Fixing line and column errors

Start at the reported line and column, then check the previous line for missing commas or quotes.
If the error points to a closing brace, the issue often appears earlier in the object.

How to check JSON
  1. Lint the document to confirm valid JSON syntax.
  2. Fix the first reported error before continuing.
  3. Format the JSON for readability.
  4. Validate with a schema if structure matters.
  • Use JSON Lint to verify syntax.
  • Format only after linting passes.
  • Apply schema validation in your app or pipeline.
Practical check
  • Paste JSON into a lint tool.
  • Fix the first line and column error.
  • Re-run lint until it passes.
  • Validate with a schema if required.

FAQ

Does JSON lint check schema rules? No. Linting checks syntax only. Schema validators enforce required keys and types.

Why does linting point at the wrong line? The location marks where parsing stopped. The real issue is often one line above.

Should I format before linting? No. Many formatters require valid JSON and may obscure the original error.

Guide end - You can now lint JSON, interpret errors, and choose the right validation step.Back to top