JSON Validation — Complete Guide

Invalid JSON breaks APIs, config files, and data pipelines. This guide shows you how to validate JSON, fix common errors, and use JSON Schema for structural validation.

Free Online JSON Formatter & Validator

Validate JSON instantly with error highlighting and line numbers. Free and private.

Open JSON Formatter & Validator →

What is JSON validation?

JSON validation checks that a JSON string conforms to the JSON specification (RFC 8259). A JSON validator tells you whether your JSON is syntactically correct and, if not, exactly where the error is.

There are two levels of JSON validation:

Most common JSON errors

ErrorExample (broken)Fix
Unquoted key{name: "Ada"}{"name": "Ada"}
Single quotes{'name': 'Ada'}{"name": "Ada"}
Trailing comma{"a": 1, "b": 2,}{"a": 1, "b": 2}
Missing comma{"a": 1 "b": 2}{"a": 1, "b": 2}
Comments{"a": 1 // comment}Remove comments (JSON has none)
undefined value{"a": undefined}Use null instead
Unescaped quotes{"a": "He said "hi""}Escape as \"
NaN / Infinity{"a": NaN}Use null or a number string

For a step-by-step repair walkthrough, see how to fix invalid JSON.

How to validate JSON online

  1. Open the JSON Formatter & Validator
  2. Paste your JSON into the input panel
  3. Click Format — any errors are highlighted with the line number and a description
  4. Fix the error and revalidate
Private: The validator runs entirely in your browser. Your JSON never leaves your machine — safe for API keys, tokens, and sensitive payloads.

Validate JSON in code

JavaScript — try/catch
function isValidJSON(str) {
  try {
    JSON.parse(str);
    return true;
  } catch (e) {
    return false;
  }
}

// With error message
function validateJSON(str) {
  try {
    return { valid: true, data: JSON.parse(str) };
  } catch (e) {
    return { valid: false, error: e.message };
  }
}

For more JavaScript examples, see how to validate JSON in JavaScript.

Python
import json

def validate_json(text):
    try:
        data = json.loads(text)
        return {"valid": True, "data": data}
    except json.JSONDecodeError as e:
        return {"valid": False, "error": str(e), "line": e.lineno}

JSON Schema validation

Syntax validation only tells you if the JSON is parseable. JSON Schema lets you define the exact structure you expect — required fields, data types, formats, and constraints — and validate any JSON document against that schema.

Example JSON Schema
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "object",
  "required": ["id", "name", "email"],
  "properties": {
    "id": { "type": "integer" },
    "name": { "type": "string", "minLength": 1 },
    "email": { "type": "string", "format": "email" },
    "age": { "type": "integer", "minimum": 0, "maximum": 150 }
  },
  "additionalProperties": false
}

Frequently asked questions

What is the difference between JSON and JSONC?
JSONC (JSON with Comments) is a superset of JSON that allows // and /* */ comments. It's used in VS Code configuration files (settings.json, tsconfig.json). Standard JSON parsers reject JSONC — you need a JSONC-aware parser to handle it.
Can JSON contain duplicate keys?
The JSON specification doesn't explicitly forbid duplicate keys, but most parsers treat it as undefined behaviour — often only keeping the last value. Avoid duplicate keys as they cause inconsistent behaviour across different parsers and languages.
Why doesn't JSON support comments?
JSON was designed as a minimal data interchange format. Comments were deliberately excluded to prevent them being used for parsing directives. If you need comments in config files, consider YAML or TOML instead.

Try it now — free & private

Runs entirely in your browser. No sign-up, no uploads, no tracking.

Open JSON Formatter & Validator →

Related tools & guides