Paste any JSON to instantly check its syntax, identify errors by line number, and format it for readability. Free, private, no signup required.
JSON validation is the process of checking that a piece of text conforms to the JSON specification (ECMA-404 / RFC 8259). Valid JSON must follow strict rules about syntax: keys must be double-quoted strings, values must be one of six types (string, number, boolean, null, array, or object), arrays and objects must be properly closed, and trailing commas are not permitted.
JSON validation is one of the most frequent tasks in everyday API development. You need it when:
The JSON validator on JSON Web Tools highlights the exact line and column where a syntax error was detected, making it fast to locate and fix problems even in large JSON documents.
This is the most frequent JSON error. Standard JSON does not allow a comma after the last element in an object or array. Many developers coming from JavaScript (which allows trailing commas) make this mistake.
// Invalid JSON
{ "name": "Alice", "age": 30, }
// Valid JSON
{ "name": "Alice", "age": 30 }
JSON requires double quotes for both keys and string values. Single quotes are JavaScript syntax, not JSON syntax.
// Invalid JSON
{ 'name': 'Alice' }
// Valid JSON
{ "name": "Alice" }
In JavaScript object literals, keys can be unquoted. In JSON, all keys must be quoted strings.
// Invalid JSON
{ name: "Alice" }
// Valid JSON
{ "name": "Alice" }
JSON does not have a comment syntax. Comments that work in JavaScript (// ... or /* ... */) will cause a parse error in JSON. If you need comments in configuration files, use JSONC (JSON with Comments) format and a parser that supports it.
These are JavaScript values that have no JSON equivalent. undefined, NaN, and Infinity in a JSON string will cause a validation failure. Use null or a sentinel numeric value instead.
Every element in an array and every key-value pair in an object (except the last one) must be followed by a comma.
// Invalid JSON
{ "name": "Alice" "age": 30 }
// Valid JSON
{ "name": "Alice", "age": 30 }
The validator also prettifies your JSON - adding consistent indentation and line breaks - which makes large, minified JSON documents much easier to read and debug.
Free, instant, 100% private. No account needed.
JSON is strict about syntax. A single misplaced comma, missing quote, or wrong data type will cause the entire document to be invalid. The validator catches these errors instantly.
// INVALID — trailing comma
{"name": "Alice", "age": 30,}
// INVALID — single quotes
{'name': 'Alice'}
// INVALID — unquoted key
{name: "Alice"}
// INVALID — comment
{"name": "Alice" /* user */}
// VALID
{"name": "Alice", "age": 30}
| Error Type | Example | Fix |
|---|---|---|
| Trailing comma | {"a":1,} | Remove the last comma |
| Single quotes | {'a':'b'} | Use double quotes |
| Unquoted key | {a: 1} | Wrap key in double quotes |
| Undefined value | {"a": undefined} | Use null instead |
| Missing comma | {"a":1 "b":2} | Add comma between pairs |
| Extra bracket | {"a":1}} | Balance all brackets |
| NaN/Infinity | {"x": NaN} | Use null or a number string |
| JS comment | {"a":1 // note} | Remove comments (not valid JSON) |
Also useful: JSON Repair Tool | CSV to JSON Converter | JWT Decoder | JSON Guides
JSON syntax is strict. Even a single misplaced character will cause a parse failure. Here are the 10 errors that account for the vast majority of invalid JSON in the wild — each with a before-and-after example.
{"a":1,} → {"a":1} — Remove the comma after the last element{'key':'val'} → {"key":"val"} — JSON requires double quotes everywhere{name:"Alice"} → {"name":"Alice"} — All keys must be quoted strings{"x":undefined} → {"x":null} — undefined is a JavaScript concept; use null{"a":1 "b":2} → {"a":1,"b":2} — Each key-value pair must be comma-separated{"a":1 // note} → {"a":1} — Comments are not valid JSON; remove them entirely{"x":NaN} → {"x":null} — Use null or a numeric string instead{"msg":"say "hi""} → {"msg":"say \"hi\""} — Escape double quotes inside strings with \"\t or \n escape sequences instead{"a":1} extra → {"a":1} — JSON must have exactly one root value with nothing after itEvery major language has a built-in or standard-library way to validate JSON. Here is the idiomatic pattern in each:
function isValidJSON(str) {
try {
JSON.parse(str);
return true;
} catch (e) {
return false;
}
}
// With error detail
function validateJSON(str) {
try {
const parsed = JSON.parse(str);
return { valid: true, data: parsed };
} catch (e) {
return { valid: false, error: e.message };
}
}
import json
def validate_json(text):
try:
data = json.loads(text)
return True, data, None
except json.JSONDecodeError as e:
return False, None, str(e)
valid, data, err = validate_json('{"name": "Alice"}')
print(valid) # True
<?php
function isValidJSON(string $str): bool {
json_decode($str);
return json_last_error() === JSON_ERROR_NONE;
}
// PHP 8.3+: json_validate() built-in
$valid = json_validate('{"name": "Alice"}'); // true
# Returns exit code 0 for valid, non-zero for invalid
echo '{"name":"Alice"}' | jq . > /dev/null 2>&1
if [ $? -eq 0 ]; then echo "Valid JSON"; else echo "Invalid JSON"; fi
# Validate a file
jq . myfile.json > /dev/null 2>&1 && echo "Valid" || echo "Invalid"
package main
import (
"encoding/json"
"fmt"
)
func isValidJSON(s string) bool {
var js json.RawMessage
return json.Unmarshal([]byte(s), &js) == nil
}
func main() {
fmt.Println(isValidJSON(`{"name":"Alice"}`)) // true
fmt.Println(isValidJSON(`{name:"Alice"}`)) // false
}
There are two distinct types of JSON validation. A basic JSON validator checks syntax — is this valid JSON? A JSON Schema validator checks structure and semantics — does this JSON match a defined shape? Understanding the difference helps you choose the right tool for the job.
| Feature | JSON Validator | JSON Schema Validator |
|---|---|---|
| What it checks | Syntax only — is this valid JSON? | Structure, types, required fields, value constraints |
| Input needed | Just the JSON string | JSON string + a JSON Schema definition |
| Error messages | Syntax error at line/column | "field 'age' must be a number", "missing required property 'email'" |
| Use case | Debugging malformed JSON; quick sanity check | API contract validation; config file validation; CI/CD checks |
| Speed | Very fast — single parse pass | Slower — walks the entire document against the schema |
| Example error | "Unexpected token } at position 12" | "$.user.age: must be >= 0" |
In practice, you need both: run a JSON validator first to ensure parseable JSON, then run a schema validator to ensure the data matches your application's expected shape. This tool handles the first step — see our JSON Schema Tutorial for the second.