How to Validate JSON: Tools and Best Practices

Invalid JSON is one of the most frustrating data problems โ€” everything looks right until something breaks. Here is how to catch errors before they cause issues downstream.

JSON validation is the process of checking that a JSON document is correctly formatted and, optionally, that it conforms to a specific structure. There are two distinct levels of validation, and understanding the difference helps you choose the right tool for the job.

Syntax Validation vs Schema Validation

TypeWhat It ChecksExample Tool
Syntax validationIs this valid JSON? Correct brackets, quotes, commas.JSONLint, browser console
Schema validationDoes this JSON have the right structure and data types?JSON Schema + Ajv, Postman

Most day-to-day issues are syntax errors. Schema validation is used in production systems where the shape of the data matters โ€” for example, ensuring an API response always includes a required userId field of type string.

The Most Common JSON Syntax Errors

1. Trailing Commas

This is the single most common JSON mistake, especially among people who write JavaScript regularly where trailing commas are allowed:

// Invalid JSON
{
  "name": "Alice",
  "age": 30,   โ† trailing comma
}

// Valid JSON
{
  "name": "Alice",
  "age": 30
}

2. Single Quotes Instead of Double Quotes

// Invalid JSON
{ 'name': 'Alice' }

// Valid JSON
{ "name": "Alice" }

3. Unquoted Keys

// Invalid JSON
{ name: "Alice" }

// Valid JSON
{ "name": "Alice" }

4. Mismatched Brackets

Every opening { needs a closing }, and every [ needs a ]. In large JSON files this is easy to miss.

// Invalid โ€” missing closing bracket
{
  "users": [
    { "name": "Alice" },
    { "name": "Bob" }
  // โ† missing ]
}

5. Comments in JSON

JSON does not support comments. This surprises many developers coming from JavaScript:

// Invalid JSON โ€” comments not allowed
{
  // This is the user's name
  "name": "Alice"
}

6. Incorrect Number Formats

JSON numbers cannot have leading zeros, and infinity/NaN are not valid:

// Invalid
{ "count": 007 }         // leading zeros
{ "ratio": Infinity }    // Infinity not supported
{ "value": NaN }         // NaN not supported

// Valid
{ "count": 7 }
{ "ratio": 1.7e308 }

Best Free JSON Validators

JSONLint

The most widely used online JSON validator. Paste your JSON, click Validate, and it highlights the exact line and character of any error with a clear explanation. Handles large files well.

Browser Developer Console

Every browser has a JavaScript console (press F12). You can validate JSON instantly by typing:

JSON.parse('{ "name": "Alice" }')

If the JSON is valid, it returns the parsed object. If not, it throws a SyntaxError with the position of the error. This is the fastest method when you are already in a browser.

VS Code with Built-in JSON Language Server

VS Code automatically validates JSON files as you type. Red underlines indicate syntax errors, and hovering over them shows a description of the problem. This is the best option when editing JSON files locally.

Command Line with Python

Python ships with a built-in JSON validator accessible from the terminal:

python -m json.tool data.json

This prints the formatted JSON if it is valid, or a clear error message if not. Useful for validating files in scripts or CI pipelines.

Node.js

node -e "JSON.parse(require('fs').readFileSync('data.json', 'utf8'))"

Returns exit code 0 on success, non-zero on error โ€” ideal for shell scripts.

Schema Validation with JSON Schema

Syntax validation only checks that the JSON is well-formed. Schema validation goes further by checking that the data has the right structure โ€” correct field names, types, and required properties.

A JSON Schema is itself a JSON document that describes the expected shape of your data:

{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "object",
  "required": ["name", "age"],
  "properties": {
    "name": { "type": "string" },
    "age":  { "type": "integer", "minimum": 0 },
    "email": { "type": "string", "format": "email" }
  }
}

This schema requires a name string and a non-negative integer age. Any JSON document that does not match these constraints will fail validation.

Tools for Schema Validation

  • Ajv โ€” the fastest JavaScript JSON Schema validator, widely used in Node.js
  • jsonschema โ€” Python library for JSON Schema validation
  • Postman โ€” validates API response bodies against schemas in automated test collections
  • JSON Schema Faker โ€” generates sample data from a schema, useful for testing

Validating JSON Before Converting to Excel

When you are converting JSON to Excel, validating the file first saves a lot of trouble. Invalid JSON will cause converters to fail or produce incomplete output. The main things to check before conversion are:

  1. Is it syntactically valid? Run it through a validator before uploading.
  2. Is it an array at the top level? Most converters expect an array of objects, not a single object.
  3. Are the keys consistent across objects? Inconsistent keys create sparse columns with many empty cells.
  4. Are there deeply nested objects? These will be flattened โ€” decide in advance whether that output is what you need.
Quick check: Open your JSON file in a browser (drag it into a tab). If the browser renders a formatted tree view, the JSON is syntactically valid. If it shows an error page, there is a syntax problem to fix first.

Fixing Malformed JSON Automatically

If you are receiving JSON from an external source that occasionally has minor formatting issues (like trailing commas), you have a few options:

  • JSON5 โ€” a superset of JSON that allows comments, trailing commas, and unquoted keys. Parse with the json5 library and re-serialize as standard JSON.
  • HJSON โ€” a human-friendly JSON format with similar relaxed rules.
  • Python's demjson3 โ€” a Python library that can parse and repair some malformed JSON.

For critical production data pipelines, always enforce strict validation and reject malformed input rather than trying to auto-repair it. Silent data corruption is worse than a visible error.

Ready to Convert Your JSON?

Our converter validates your JSON automatically before converting โ€” no extra steps needed.

Convert JSON to Excel Now โ†’