ConvertCSV

How to Validate JSON: Syntax, Schema, and Real-World Checks

By Convert CSV Editorial TeamLast updated August 1, 2026

Validate JSON syntax and structure. Use online tools, JSON Schema, and code examples to catch errors before your API or database does.

Two Levels of JSON Validation

There is a big difference between "is this valid JSON?" and "does this JSON match the shape my API expects?". Both matter.

Syntax validation catches trailing commas and mismatched braces. Schema validation catches missing fields, wrong types, and business-rule violations. Ship both in production pipelines.

LevelCatches
SyntaxParse errors: trailing commas, unquoted keys, mismatched brackets
SchemaShape errors: missing fields, wrong types, enum violations
SemanticBusiness rules: unique IDs, cross-field constraints

Syntax Validation: Quick and Easy

The fastest check is a JSON parser. If parse fails, your JSON is invalid.

In the browser (JS)

JSON.parse throws on the first syntax error.

try {
  const data = JSON.parse(text);
} catch (err) {
  console.error("Invalid JSON:", err.message);
}

In Python

json.loads raises JSONDecodeError.

import json
try:
    data = json.loads(text)
except json.JSONDecodeError as e:
    print("Invalid JSON:", e.msg, "line", e.lineno, "col", e.colno)

In the terminal (jq)

jq is a great sanity check.

jq . data.json > /dev/null && echo OK || echo BAD

Schema Validation with JSON Schema

JSON Schema is a small JSON vocabulary that describes what valid JSON looks like. It powers OpenAPI, Ajv, and most production validation.

{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "object",
  "required": ["order_id", "email", "amount"],
  "properties": {
    "order_id": { "type": "string", "pattern": "^[0-9]+$" },
    "email":    { "type": "string", "format": "email" },
    "amount":   { "type": "number", "minimum": 0 }
  },
  "additionalProperties": false
}

Validate with Ajv (Node.js)

Ajv is the standard JSON Schema validator in JS.

import Ajv from "ajv";
import addFormats from "ajv-formats";
const ajv = new Ajv({ allErrors: true });
addFormats(ajv);

const validate = ajv.compile(schema);
if (!validate(data)) {
  console.error(validate.errors);
}

Validate with jsonschema (Python)

Same idea in Python.

from jsonschema import validate, ValidationError

try:
    validate(instance=data, schema=schema)
except ValidationError as e:
    print("Invalid:", e.message)

Common JSON Errors You Can Prevent

The same three culprits produce most parse errors.

  • Trailing commas inside objects and arrays.
  • Single quotes instead of double quotes.
  • Unquoted keys (a JavaScript object literal habit).
  • Unescaped newlines inside strings.
  • Duplicate keys inside the same object.

Validating CSV-Derived JSON

When JSON comes from a spreadsheet or CSV export, expect these headaches: string "true" instead of boolean true, IDs that are strings and numbers in the same file, and missing fields for optional columns.

Use a schema with type coercion turned off so you catch these at ingest instead of later.

Real-World Examples

Where validation pays off.

API gateway

Reject invalid payloads before they hit business logic; return a helpful error listing the failing fields.

ETL pipeline

Validate every batch of records before writing to the warehouse; quarantine bad rows for review.

CI check

Validate committed JSON fixtures during CI so a bad fixture never ships.

Common Mistakes

The habits that cost teams the most time.

  • Only validating syntax and skipping schema.
  • Writing schemas without required/enum/pattern.
  • Ignoring additionalProperties and letting typos through.
  • Turning off strict mode to make errors go away.
  • Validating on the way out of your app instead of on the way in.

Best Practices

The playbook that scales.

  • Validate at every trust boundary.
  • Keep schemas in version control next to the code they protect.
  • Return field-level errors, not "invalid input".
  • Prefer Ajv (JS) or jsonschema (Python) over hand-rolled checks.
  • Reject unknown fields unless you explicitly allow them.

Why Use Convert CSV Online?

Convert CSV Online is free, browser-based, and requires no account for everyday conversions. Turn CSVs into JSON and inspect them in the Online CSV Editor. Once the JSON parses cleanly, run schema validation in your app to catch shape errors. Client-side workflows work on Windows, macOS, and Linux browsers.

Fewer surprises downstream

Validating early means dashboards, APIs, and ML pipelines get clean input every time.

Conclusion

Validate JSON syntax with the built-in parser and validate shape with JSON Schema. The two checks together catch almost every real-world bug before it becomes a production incident.

FAQ

How do I validate JSON?

Parse it first (JSON.parse or json.loads) for syntax, then validate against a JSON Schema for shape and business rules.

What is JSON Schema?

A JSON vocabulary for describing the shape and constraints of JSON documents—types, required fields, patterns, enums, and more.

Which JSON Schema validator should I use?

Ajv is the standard for JavaScript/TypeScript, and jsonschema is the popular Python option. Both support recent JSON Schema drafts.

How do I fix trailing commas in JSON?

Remove them. Standard JSON does not allow trailing commas. Use a linter or your editor’s JSON support to catch them.

Can I comment JSON?

Strict JSON has no comments. Use JSON5 or JSONC if you need comments, but be aware they are not standard JSON.

How do I validate JSON in the browser?

Use JSON.parse for syntax and Ajv for schema. Both run entirely in the browser.

References

Convert your CSV in the browser

Preview, clean, and convert CSV files free with Convert CSV Online—no installation and no account required for everyday conversions.