How to Validate JSON Online: Tools and Methods 2026
Published: 2026-05-16 • Category: Developer Tools / JSON / Web Development
Why Validate JSON?
JSON (JavaScript Object Notation) is the most widely used data format on the web. APIs, configuration files, databases, and data pipelines all rely on well-formed JSON. A single missing comma, extra bracket, or unquoted string can break your entire application. That's why validating JSON before using it is a critical step in any development workflow.
This guide covers every way to validate JSON — from free online tools to programmatic validation in JavaScript, Python, and the command line. Whether you're debugging an API response, checking a config file, or building a data pipeline, you'll find the right method here.
Method 1: Online JSON Validators (Fastest)
The quickest way to check if your JSON is valid is to use an online tool. Simply paste your JSON and get instant feedback.
EasyTool.me JSON Formatter — Paste your JSON, and it will instantly format, validate, and highlight any errors. It runs entirely in your browser, so your data never leaves your device. Key features include:
- Instant validation — errors are highlighted as you type
- Error position — shows exactly which line and character has the problem
- Pretty print — formats valid JSON with proper indentation
- Minify — compresses JSON for production use
- Privacy-first — all processing happens locally in your browser
Other popular online validators include JSONLint, JSON Formatter & Validator (jsonformatter.org), and CodeBeautify. All work similarly — paste your JSON and get instant validation.
Method 2: JavaScript — JSON.parse()
In JavaScript, the built-in JSON.parse() method is the standard way to validate JSON. If the string is not valid JSON, it throws a SyntaxError.
function isValidJSON(str) {
try {
JSON.parse(str);
return true;
} catch (e) {
return false;
}
}
// Usage
console.log(isValidJSON('{"name": "Alice", "age": 30}')); // true
console.log(isValidJSON('{name: "Alice"}')); // false
console.log(isValidJSON('{"name": "Alice",}')); // false (trailing comma)
To get detailed error information:
function validateJSON(str) {
try {
const parsed = JSON.parse(str);
return { valid: true, data: parsed };
} catch (e) {
return {
valid: false,
error: e.message,
position: e.message.match(/position (\d+)/)?.[1]
};
}
}
const result = validateJSON('{"name": "Alice", "age":}');
console.log(result);
// { valid: false, error: "Expected ':' after property name...", position: 24 }
Method 3: Python — json.loads()
Python's json module provides json.loads() for parsing and validating JSON strings.
import json
def is_valid_json(text):
try:
json.loads(text)
return True
except json.JSONDecodeError as e:
print(f"Invalid JSON: {e}")
return False
# Usage
print(is_valid_json('{"name": "Alice", "age": 30}')) # True
print(is_valid_json("{'name': 'Alice'}")) # False (single quotes)
print(is_valid_json('{"name": "Alice",}')) # False (trailing comma)
For detailed error reporting with line and column numbers:
import json
def validate_json_detailed(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,
"column": e.colno,
"position": e.pos
}
result = validate_json_detailed('{"name": "Alice"\n"age": 30}')
print(result)
# {'valid': False, 'error': 'Expecting : delimiter', 'line': 1, 'column': 16, 'position': 16}
Method 4: Command Line — jq
The jq command-line tool is excellent for validating JSON in scripts and CI/CD pipelines.
# Validate a JSON file
echo '{"name": "Alice"}' | jq empty
# If invalid, jq prints an error:
echo '{name: Alice}' | jq empty
# parse error: Invalid numeric literal at line 1, column 6
# Validate and pretty-print
cat config.json | jq .
# Check validity in a script
if jq empty config.json 2>/dev/null; then
echo "Valid JSON"
else
echo "Invalid JSON"
fi
Python's json.tool module also works as a command-line validator:
# Validate using Python's json.tool
echo '{"name": "Alice"}' | python3 -m json.tool
# Invalid JSON produces an error
echo '{invalid}' | python3 -m json.tool
# Expecting property name enclosed in double quotes
Method 5: JSON Schema Validation
Syntax validation only checks if the JSON is well-formed. JSON Schema validates the structure and content — checking that required fields exist, values are the right type, and constraints are met.
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
"required": ["name", "email"],
"properties": {
"name": { "type": "string", "minLength": 1 },
"email": { "type": "string", "format": "email" },
"age": { "type": "integer", "minimum": 0, "maximum": 150 }
},
"additionalProperties": false
}
Validate against a schema in Python using jsonschema:
from jsonschema import validate, ValidationError
schema = {
"type": "object",
"required": ["name", "email"],
"properties": {
"name": {"type": "string"},
"email": {"type": "string"},
"age": {"type": "integer"}
}
}
try:
validate(instance={"name": "Alice", "email": "alice@example.com"}, schema=schema)
print("Valid!")
except ValidationError as e:
print(f"Validation error: {e.message}")
Common JSON Errors and How to Fix Them
Here are the most frequent JSON mistakes and their solutions:
1. Trailing Commas
// WRONG — trailing comma
{"name": "Alice", "age": 30,}
// CORRECT
{"name": "Alice", "age": 30}
2. Single Quotes Instead of Double Quotes
# WRONG — single quotes
{'name': 'Alice'}
# CORRECT — double quotes
{"name": "Alice"}
3. Unquoted Keys
// WRONG — unquoted key
{name: "Alice"}
// CORRECT
{"name": "Alice"}
4. Comments in JSON
// WRONG — JSON does not support comments
{
"name": "Alice" // this is a comment
}
// CORRECT — remove comments or use JSONC/JSON5
{"name": "Alice"}
5. Missing Commas Between Items
// WRONG — missing comma
{"name": "Alice" "age": 30}
// CORRECT
{"name": "Alice", "age": 30}
Automated Validation in CI/CD
Add JSON validation to your CI/CD pipeline to catch errors before deployment:
# GitHub Actions example
name: Validate JSON
on: [push]
jobs:
validate:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Validate all JSON files
run: |
find . -name "*.json" -exec python3 -m json.tool {} \;
Frequently Asked Questions
Is JSON with comments valid?
No. The official JSON specification (RFC 8259) does not support comments. If you need comments, use JSONC (JSON with Comments) or JSON5, which are JSON supersets supported by many tools and editors.
Can JSON have single quotes?
No. The JSON specification requires double quotes for both keys and string values. Single quotes are valid in JavaScript objects but not in JSON.
What's the difference between null, undefined, and empty string in JSON?
null is a valid JSON value representing nothing. undefined is not valid in JSON (it's a JavaScript concept). An empty string "" is valid JSON but represents an empty text value, not nothing.
How do I validate very large JSON files?
For large files (100MB+), use streaming parsers like jq or Python's ijson library instead of loading the entire file into memory.
Is there a difference between JSON and JSON5?
Yes. JSON5 is a superset of JSON that allows comments, trailing commas, unquoted keys, and other relaxed syntax rules. It's commonly used for configuration files but is not a replacement for standard JSON in APIs.
Quick Reference: Validate JSON in Every Language
- JavaScript:
JSON.parse(str) - Python:
json.loads(str) - Java:
new JSONObject(str)or JacksonObjectMapper - Go:
json.Valid([]byte(str)) - Ruby:
JSON.parse(str) - PHP:
json_decode($str) !== null - C#:
JsonDocument.Parse(str) - Rust:
serde_json::from_str::<Value>(str) - Command Line:
echo '{}' | jq empty
Try it now: Use the EasyTool.me JSON Formatter to validate, format, and beautify your JSON instantly. No signup, no upload — runs entirely in your browser.