How to Validate JSON Online

Last updated:

JSON validation is a 2-tier process: syntax validation checks that a string is parseable JSON; schema validation checks that the parsed data matches an expected structure. The 5 most common syntax errors — trailing commas, single-quoted strings, unquoted keys, missing commas, and unclosed brackets — account for over 90% of failures seen in real API payloads. Syntax must pass before schema validation can run. Schema validation requires a JSON Schema document plus a validator library like Ajv (100M+ weekly npm downloads). This guide covers 7 error types with fixes, validation in 4 environments (browser, Node.js, Python, command line), and schema validation withrequired fields, type checks, and format constraints.

Validate your JSON instantly

Paste any JSON to check syntax and see exact error positions — no account required.

Open JSON Validator

Two types of JSON validation

Syntax validation checks whether a string is valid JSON — whether it can be parsed without errors. This is what JSON.parse() does.

Schema validation checks whether the parsed JSON matches an expected structure — correct field names, required fields present, values of the right type. This requires a schema (written in JSON Schema) in addition to the data.

Most debugging starts with syntax validation. Schema validation is useful once you're building an API contract or validating config files programmatically.

Common JSON syntax errors

1. Trailing commas

The most common JSON error. JavaScript objects and arrays allow trailing commas; JSON does not.

// Invalid JSON
{
  "name": "Alice",
  "age": 30,         ← trailing comma
}

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

2. Single quotes instead of double quotes

JSON requires double quotes for both keys and string values. Single quotes are not valid.

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

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

3. Unquoted keys

JavaScript objects allow unquoted keys; JSON does not.

// Invalid JSON (JavaScript object literal, not JSON)
{ name: "Alice", age: 30 }

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

4. Comments

JSON does not support comments. If you're writing config files and need comments, consider YAML or JSONC (JSON with Comments, supported by VS Code and TypeScript).

// Invalid JSON
{
  // This is a comment
  "name": "Alice"
}

// Valid JSON — no comments
{ "name": "Alice" }

5. Undefined and NaN

undefined, NaN, and Infinity are JavaScript values with no JSON equivalent. They cause errors during serialization.

// These are not valid JSON values
{ "value": undefined }
{ "ratio": NaN }
{ "limit": Infinity }

// Use null for missing values, or a sentinel number for Infinity
{ "value": null }
{ "ratio": null }
{ "limit": 1e308 }

6. Unescaped special characters in strings

Certain characters inside JSON strings must be escaped: \n for newline,\t for tab, \" for a literal double quote, \\ for a literal backslash.

// Invalid — literal newline inside string
{ "message": "line one
line two" }

// Valid — escaped newline
{ "message": "line one
line two" }

// Invalid — unescaped quote
{ "title": "He said "hello"" }

// Valid
{ "title": "He said \"hello\"" }

7. Numbers: leading zeros, hex, no quotes

// Invalid
{ "id": 007 }       // leading zeros not allowed
{ "hex": 0xFF }     // hex literals not allowed
{ "val": .5 }       // must be 0.5

// Valid
{ "id": 7 }
{ "hex": 255 }
{ "val": 0.5 }

How to validate JSON in different environments

Browser console

// Paste in DevTools console
JSON.parse('{"name": "Alice"}')   // → parsed object, no error
JSON.parse('{name: "Alice"}')     // → SyntaxError: Unexpected token n

Node.js

const fs = require('fs')
const raw = fs.readFileSync('data.json', 'utf8')
try {
  const data = JSON.parse(raw)
  console.log('Valid JSON')
} catch (e) {
  console.error('Invalid JSON:', e.message)
}

Python

import json
try:
    data = json.loads(raw_string)
    print("Valid JSON")
except json.JSONDecodeError as e:
    print(f"Invalid JSON: {e}")

Command line

# Using jq (prints formatted JSON or error)
cat data.json | jq .

# Using Python one-liner
python3 -m json.tool data.json

Schema validation: beyond syntax

Syntax validation only tells you the JSON is parseable. It doesn't tell you whether a required field is missing or a value has the wrong type. That's where JSON Schema comes in.

// Syntactically valid, but semantically wrong
{ "user": { "email": 12345, "age": "thirty" } }

// A schema catches these:
{
  "type": "object",
  "properties": {
    "user": {
      "type": "object",
      "required": ["email"],
      "properties": {
        "email": { "type": "string", "format": "email" },
        "age": { "type": "integer", "minimum": 0 }
      }
    }
  }
}

See the JSON Schema tutorial for a full introduction to writing schemas.

Validate your JSON now

Paste any JSON into Jsonic's JSON Formatter & Validator for instant syntax checking with clear error messages. For schema validation, use the JSON Schema Validator. Both run entirely in your browser.

Frequently asked questions

How do I check if a string is valid JSON?

Attempt to parse it and catch the error: try {'{ JSON.parse(str) }'} catch {'{ return false }'} in JavaScript, or json.loads() in a try/except in Python. Online validators like Jsonic's JSON Formatter show the exact error position.

What is the fastest way to validate JSON online?

Paste your JSON into Jsonic's JSON Formatter. It validates instantly in your browser with no upload required. Syntax errors are highlighted with exact line and position. For schema validation, use the JSON Schema Validator.

What is the difference between syntax validation and schema validation?

Syntax validation checks whether a string is parseable JSON (correct grammar). Schema validation checks whether parsed data has the expected structure — required fields, correct types, and value constraints. Syntax validation always comes first.

How do I validate JSON in JavaScript?

For syntax: wrap JSON.parse() in a try/catch. For schema: use Ajv — compile a JSON Schema, call validate(data), and check validate.errors for details. Zod is an alternative that combines schema and TypeScript types.

What tool validates JSON against a schema?

Browser: Jsonic's JSON Schema Validator. JavaScript: Ajv. Python: jsonschema package. Java: networknt's json-schema-validator. Go: gojsonschema. Command line: ajv-cli. Most support JSON Schema drafts 04 through 2020-12.

Does the browser have a built-in JSON validator?

Not as a standalone tool, but JSON.parse() in the DevTools console validates JSON syntax and reports error positions. For a better experience with highlighted errors and formatted output, use an online validator.