JSON Formatter & Validator Online
Paste your JSON to format, validate, and beautify it with proper indentation. Detects syntax errors and supports minification. All processing happens in your browser.
What Is JSON?
JSON (JavaScript Object Notation) is a lightweight, text-based data interchange format defined by RFC 8259. It is human-readable and language-independent, making it the standard format for REST APIs, configuration files, and data storage across nearly all programming ecosystems.
JSON Data Types
| Type | Example | Notes |
|---|---|---|
| String | "hello" | Must use double quotes. Escape special chars with \ |
| Number | 42, 3.14, -1e10 | No quotes. No NaN or Infinity |
| Boolean | true, false | Lowercase only |
| Null | null | Lowercase only |
| Object | {"key": "value"} | Unordered key-value pairs. Keys must be strings |
| Array | [1, 2, 3] | Ordered list of any values |
Common JSON Syntax Errors
- Trailing comma:
{"a": 1, "b": 2,}— the comma after2is invalid in JSON (but valid in JavaScript). - Single quotes:
{'key': 'value'}— JSON requires double quotes for strings and keys. - Unquoted keys:
{key: "value"}— all keys must be quoted strings. - Comments: JSON does not support
//or/* */comments. Use JSON5 or JSONC if you need comments. - NaN / Infinity: These JavaScript values are not valid JSON. Use
nullor a sentinel number instead. - Unescaped control characters: Literal newlines inside strings are invalid — use
\ninstead.
JSON Formatting in Code
JavaScript / Node.js
// Pretty print with 2-space indent
const formatted = JSON.stringify(data, null, 2);
// Minify
const minified = JSON.stringify(data);
// Parse and re-format API response
const pretty = JSON.stringify(JSON.parse(responseText), null, 2); Python
import json
# Pretty print
print(json.dumps(data, indent=2, sort_keys=True))
# Minify
print(json.dumps(data, separators=(',', ':'))) Shell (Linux/macOS)
# Format JSON file with jq
jq . data.json
# Minify
jq -c . data.json
# Extract a nested value
jq '.user.address.city' data.json JSON Schema Validation
JSON Schema is a vocabulary for annotating and validating JSON documents. It lets you define the expected structure, types, and constraints of your JSON data, enabling automated validation at API boundaries or in CI pipelines.
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
"properties": {
"name": { "type": "string", "minLength": 1 },
"age": { "type": "integer", "minimum": 0 }
},
"required": ["name"]
} Best Practices
- Use 2-space indentation for configuration files stored in version control — it is the most common convention.
- Sort keys alphabetically in config files to reduce diff noise when keys are added or removed.
- Minify JSON in production API responses to reduce payload size and improve latency.
- Validate JSON against a schema at API entry points to fail fast on malformed input.
- Use
JSON.parsein a try/catch block — never assume input is valid JSON.
Frequently Asked Questions
What is the difference between JSON formatting and validation?
Formatting adds indentation and line breaks for readability. Validation checks structural correctness — balanced braces, properly quoted keys, valid value types, no trailing commas. JSON can be valid but unformatted (minified), or well-formatted but syntactically invalid.
What are common JSON syntax errors?
The most common errors: trailing commas after the last item, single quotes instead of double quotes, unquoted keys, comments (JSON does not support them), and NaN or undefined values. This formatter highlights the exact error location to help you fix them quickly.
When should I minify JSON?
Minify JSON for network transmission (API responses, config downloads) to reduce payload size. Keep JSON pretty-printed in config files, version-controlled files, and anywhere humans need to read or edit it. A 10KB pretty-printed JSON typically compresses to 6–7KB when minified.