JSON Formatter & Validator
Format, validate, and minify JSON instantly. Paste your JSON, choose an indentation style, and see the formatted output with validation status. View statistics including key count, nesting depth, and byte size.
Paste JSON above to format and validate
JSON Formatting and Validation: A Developer's Guide to Working with JSON
JSON (JavaScript Object Notation) is the dominant data interchange format on the modern web. Originally derived from JavaScript object literal syntax, JSON has become language-independent and is supported natively by virtually every programming language and platform. APIs, configuration files, database documents, and message queues all rely on JSON as their primary serialization format. Yet despite its simplicity, malformed JSON is one of the most common sources of bugs in web applications — a misplaced comma, a missing bracket, or an unescaped string can silently break an entire data pipeline.
JSON Syntax Rules
JSON supports six data types: strings (double-quoted), numbers, booleans (true/false), null, arrays (ordered lists in square brackets), and objects (unordered key-value pairs in curly braces). Keys in objects must be double-quoted strings. Single quotes, trailing commas, and comments are not allowed — these are common sources of syntax errors for developers accustomed to JavaScript, which permits all three.
Strings must use double quotes and can contain Unicode escape sequences (\u0041 for 'A'). Special characters within strings must be escaped: backslash (\\), double quote (\"), forward slash (\/), backspace (\b), form feed (\f), newline (\n), carriage return (\r), and tab (\t). Numbers follow the same rules as JavaScript: integer or floating point, with optional negative sign and optional exponent notation (1.5e10). Octal and hexadecimal number literals are not valid JSON.
Whitespace between tokens (spaces, tabs, newlines) is insignificant in JSON. A minified file with no whitespace and a beautifully formatted file with consistent indentation contain identical data. This is why formatting tools can safely transform JSON without altering its meaning — they only change the whitespace between structural tokens.
Why Format JSON?
API responses, log entries, and configuration files often contain deeply nested JSON structures that are difficult to read when compressed into a single line. Formatting — also called pretty-printing — adds line breaks and indentation to make the hierarchical structure visible at a glance. A well-formatted JSON document reveals its schema: you can immediately see which keys exist, how deeply objects are nested, and where arrays begin and end.
Consistent formatting also matters for version control. When a team commits formatted JSON files to Git, each key-value pair occupies its own line. This means that adding, removing, or modifying a single field produces a clean, minimal diff — one line changed, not the entire file. Minified JSON in version-controlled files produces unreadable diffs that obscure what actually changed.
Minification: When Small Size Matters
While formatting makes JSON readable, minification makes it compact. Minified JSON has all unnecessary whitespace removed, resulting in the smallest possible representation. This is important for network transmission, where every byte counts — especially in high-throughput APIs serving millions of requests per second.
A typical JSON API response might be 30-50% smaller when minified compared to 2-space formatted. For a 10 KB response, that saves 3-5 KB per request. At scale — thousands of requests per second — this bandwidth saving is significant. Most web frameworks and API gateways minify JSON responses automatically, but understanding the tradeoff between readability and size helps developers make informed choices in their own tools and configurations.
Common JSON Errors and How to Fix Them
Trailing commas are the most frequent JSON syntax error. JavaScript allows {"a": 1, "b": 2,} with a trailing comma after the last element, but JSON does not. Remove the trailing comma before the closing brace or bracket.
Single-quoted strings are valid JavaScript but not valid JSON. All strings and keys must use double quotes. Replace 'value' with "value" throughout your document. Missing quotes around keys — {name: "value"} instead of {"name": "value"} — is another common mistake.
Unescaped special characters inside strings cause parsing failures. Newlines, tabs, and backslashes within string values must be escaped as \n, \t, and \\ respectively. This formatter shows the exact error message from the JSON parser, which typically includes the character position where parsing failed — useful for locating the problem in large documents.
JSON in Configuration Files
Many tools use JSON for configuration: package.json in Node.js, tsconfig.json in TypeScript, .eslintrc.json in ESLint, and settings.json in VS Code. These files are typically edited by hand and read by machines, which creates a tension between human readability and strict syntax compliance.
Some configuration formats — such as JSON5 and JSONC (JSON with Comments) — extend JSON to allow comments, trailing commas, and single-quoted strings. TypeScript's tsconfig.json actually uses JSONC, which is why you can add comments there but not in package.json. When working with strict JSON files, this formatter helps verify that your hand-edited configuration is syntactically valid before committing it.
Working with Large JSON Documents
This formatter processes JSON entirely in the browser using JavaScript's native JSON.parse and JSON.stringify functions. For typical documents (up to a few megabytes), this is fast and efficient. For very large documents — database dumps, analytics exports, or API responses with thousands of records — browser-based tools may become slow due to memory constraints.
For large-scale JSON processing, command-line tools like jq provide streaming parsers that can handle multi-gigabyte files without loading them entirely into memory. Python's json.tool module (python -m json.tool) and Node.js scripts can also process large files efficiently. For everyday development tasks — validating API responses, formatting configuration files, debugging webhook payloads — this browser-based tool provides the fastest feedback loop.
Frequently Asked Questions
Why is my JSON invalid?
The most common causes of invalid JSON are: trailing commas after the last element in an array or object, single-quoted strings instead of double quotes, unquoted keys, unescaped special characters in strings (newlines, tabs, backslashes), and comments (JSON does not support comments). The error message shown by this tool includes the character position where parsing failed, which helps locate the exact problem.
What is the difference between 2-space and 4-space indentation?
Both produce valid, identical JSON data — only the whitespace changes. 2-space indentation is more compact and is the default for most JavaScript and web projects (npm, Prettier, ESLint). 4-space indentation provides more visual separation and is common in Python and Java projects. The choice is a team or project convention with no functional difference.
Does minifying JSON change the data?
No. Minification only removes whitespace (spaces, tabs, newlines) between JSON tokens. The data values, keys, structure, and ordering are all preserved exactly. A minified JSON string and a formatted JSON string with identical content will produce the same result when parsed by any JSON parser.
Can JSON have comments?
Standard JSON (RFC 8259) does not support comments. This is an intentional design decision to keep the format simple and unambiguous. Some tools support JSONC (JSON with Comments) or JSON5, which extend JSON with comments, trailing commas, and other features. TypeScript's tsconfig.json uses JSONC. If you need comments in configuration files, check whether your tool supports these extended formats.
How large a JSON file can this tool handle?
This tool processes JSON in the browser using native JSON.parse and JSON.stringify, which are highly optimized. It can comfortably handle documents up to several megabytes. For very large files (tens of megabytes or more), browser memory limits may cause slowdowns. For large-scale processing, command-line tools like jq or Python's json.tool are better suited.
Related Calculators
AI Token Cost Calculator
Estimate API costs for GPT-4o, Claude, Gemini, and other LLMs based on token usage.
AI Token & Word Count Calculator
Convert between AI tokens, words, and characters with cost estimation.
API Rate Limit Calculator
Plan your API usage by calculating max throughput, operations per day, delay between requests, and burst capacity.