JSON Formatter & Validator
Paste your JSON into this JSON formatter to pretty-print, minify, and validate instantly. Customizable indentation, syntax highlighting, and error detection.
JSON (JavaScript Object Notation) is the most common data format for APIs, configuration files, and data exchange. Douglas Crockford originally specified the format in the early 2000s, and it is now defined by two active standards: ECMA-404 (2nd edition, December 2017) and IETF RFC 8259 (Internet Standard STD 90, also 2017). This tool formats, validates, and minifies JSON entirely in your browser. Paste raw or minified JSON, and get syntax-highlighted, properly indented output with instant error detection if anything is wrong.
About JSON Formatter & Validator
What Does the Formatter Do?
The formatter uses JSON.parse() followed by JSON.stringify() with your chosen indentation level, producing clean, consistent output. The validator catches syntax errors in real time and reports the exact error message from the browser's native parser so you can pinpoint the problem quickly. You can also switch to a collapsible tree view to explore deeply nested structures without scrolling through thousands of lines.
| Feature | What It Does |
|---|---|
| Format / Pretty-print | Adds indentation and line breaks for readability |
| Minify | Removes all whitespace for the smallest possible output |
| Validate | Reports syntax errors with error message and location |
| Syntax highlighting | Colour-codes strings, numbers, booleans, null, and keys |
| Tree view | Interactive collapsible tree with expand/collapse all, type badges, and per-node copy |
Worked example: Suppose you receive a minified API response like {"users":[{"id":1,"name":"Alice","active":true},{"id":2,"name":"Bob","active":false}]}. Pasting that into the formatter and clicking Format with 2-space indentation produces a neatly indented document where each key-value pair sits on its own line, brackets align visually, and the tree view lets you expand or collapse the "users" array independently.
Indentation Options
The choice of indentation style is mostly a team convention. The formatter supports three options:
| Style | Convention | File Size Impact |
|---|---|---|
| 2 spaces | Most common in JavaScript/TypeScript projects (Node.js, npm package.json default) | Moderate |
| 4 spaces | Common in Python and Java ecosystems (matches PEP 8, Google Java Style) | Larger |
| Tab | Some teams prefer tabs for configurable display width in editors | Moderate (1 char per level) |
For version-controlled config files, consistent indentation matters because git diffs become noisy when different editors auto-format with different styles. Pick one style for your project and stick with it.
Common JSON Errors and How to Fix Them
Most JSON errors come from copying JavaScript object literals and assuming they are valid JSON. The five most frequent mistakes:
| Error Message | Cause | Fix |
|---|---|---|
| Unexpected token | Unquoted key, single quotes, or invalid character | Use double quotes for all keys and strings |
| Trailing comma | Comma after the last item in an array or object | Remove the final comma |
| Unexpected end of input | Missing closing bracket or brace | Add the missing } or ] |
| Invalid escape | Backslash followed by an invalid character in a string | Use valid escapes: \n, \t, \\, \", \/ |
| Unexpected number | Leading zeros (e.g., 007) | Remove leading zeros, or use the string "007" |
Another common source of errors is copying JSON from documentation that uses "smart quotes" (curly quotes). Word processors and some websites automatically replace straight quotes with curly ones, which are not valid JSON characters. If you see an "unexpected token" error and the JSON looks correct, check for invisible curly quotes or non-breaking spaces.
JSON Syntax Rules
Valid JSON is stricter than JavaScript object literal syntax. This catches out many developers who write JS objects daily but rarely hand-author JSON. The key differences, as defined by RFC 8259:
| Rule | Valid JSON | Invalid JSON |
|---|---|---|
| Keys must be double-quoted | {"name": "value"} | {name: "value"} |
| Strings must use double quotes | "hello" | 'hello' |
| No trailing commas | [1, 2, 3] | [1, 2, 3,] |
| No comments | (no comment syntax) | // comment or /* comment */ |
| No undefined or NaN | null | undefined |
| Numbers cannot have leading zeros | 0.5 | 007 |
RFC 8259 also requires that JSON transmitted over a network must be encoded as UTF-8. Earlier versions of the spec allowed UTF-16 and UTF-32, but the 2017 standard narrowed this to UTF-8 only for interoperability.
JSON Data Types
JSON supports exactly six data types - four primitives and two structured types:
| Type | Example | Notes |
|---|---|---|
| String | "hello world" | Must use double quotes, supports escape sequences (\n, \t, \uXXXX) |
| Number | 42, 3.14, -1, 1e10 | Integer or float, no leading zeros, no hex, no Infinity or NaN |
| Boolean | true, false | Lowercase only (True and False are invalid) |
| Null | null | Lowercase only (NULL and None are invalid) |
| Object | {"key": "value"} | Unordered collection of key-value pairs. Keys must be strings. |
| Array | [1, 2, 3] | Ordered list of values. Can mix types. |
One common pitfall: JSON has no date type. Dates are typically stored as ISO 8601 strings (e.g., "2026-04-15T10:30:00Z") or as Unix timestamps (integer milliseconds since 1970). There is no standard, so APIs vary - always check the documentation for the API you are working with.
When to Format vs Minify
Formatting and minifying are opposite operations, and both have practical uses. A 1 MB formatted JSON file might shrink to 600-700 KB when minified, depending on nesting depth and key lengths. For API responses served at scale, that 30-40% reduction translates directly to bandwidth savings.
| Format (Pretty-Print) | Minify | |
|---|---|---|
| Use when | Reading, debugging, reviewing | Storing, transmitting, embedding |
| File size | Larger (whitespace added) | Smallest possible |
| Human readable | Yes | No |
| For config files | Formatted (cleaner version control diffs) | Minified (if deployed as data) |
| For API payloads | During development | In production |
Most web servers also apply gzip or Brotli compression on top, which largely eliminates the whitespace overhead. So formatting during development costs almost nothing in practice once the response is compressed for transit.
How Does JSON Compare to Other Data Formats?
JSON dominates API communication - REST APIs power roughly 83% of web services, and virtually all of them use JSON as their data format. But JSON is not always the best choice for every use case. JSON parsing is typically 2-10x faster than YAML parsing in most languages, while XML documents tend to be 3-4x larger than the equivalent JSON for the same data.
| Format | Readability | Comments? | Typed? | Parse Speed | Common Use |
|---|---|---|---|---|---|
| JSON | Good | No | No (schema optional) | Fastest | APIs, config, data exchange |
| YAML | Very good | Yes | No | Slower (2-10x) | Config files (Docker, K8s, CI/CD) |
| TOML | Good | Yes | Yes (dates, etc.) | Fast | Config (Rust Cargo.toml, Go) |
| XML | Moderate | Yes | Schema-based | Slower | Legacy APIs, SOAP, documents |
| CSV | Moderate | No | No | Fast | Tabular data, spreadsheets |
JSON's lack of comments is its most debated limitation. JSONC (JSON with Comments) and JSON5 are unofficial extensions that allow comments and trailing commas. TypeScript's tsconfig.json, for example, actually uses JSONC, not strict JSON. If you need comments in config files, consider YAML or TOML instead.
JSON Performance and Size Limits
This tool processes JSON entirely in your browser using the native JSON.parse() function, which is highly optimised in modern JavaScript engines. V8 (Chrome, Edge, Node.js) and SpiderMonkey (Firefox) can parse several megabytes of JSON in under a second on most devices.
For extremely large or deeply nested documents, keep these practical limits in mind:
| Concern | Typical Limit | What Happens |
|---|---|---|
| File size | ~50-100 MB in browser | Parsing slows, browser tab may run out of memory |
| Nesting depth | ~1,000 levels (parser-dependent) | Stack overflow error in recursive parsers |
| Memory overhead | 2-4x the raw text size | JavaScript objects carry type info and property management overhead |
| String length | ~512 MB (V8 limit) | RangeError for strings exceeding the engine limit |
For documents over a few megabytes, consider using a streaming parser (like JSONStream in Node.js) or processing the file in chunks rather than loading it all at once.
Working with JSON in Different Languages
Every major programming language has built-in or standard-library JSON support:
| Language | Parse | Stringify | Notes |
|---|---|---|---|
| JavaScript | JSON.parse(str) | JSON.stringify(obj, null, 2) | Built into the language since ES5 (2009) |
| Python | json.loads(str) | json.dumps(obj, indent=2) | Standard library json module |
| Java | new ObjectMapper().readTree(str) | mapper.writeValueAsString(obj) | Jackson library (most common) |
| Go | json.Unmarshal(data, &v) | json.MarshalIndent(v, "", " ") | Standard library encoding/json |
| Ruby | JSON.parse(str) | JSON.pretty_generate(obj) | Standard library json |
| PHP | json_decode($str) | json_encode($obj, JSON_PRETTY_PRINT) | Built-in functions since PHP 5.2 |
| Rust | serde_json::from_str(s) | serde_json::to_string_pretty(&v) | serde_json crate (de facto standard) |
The third argument to JSON.stringify() controls indentation. Passing 2 gives 2-space indent, 4 gives 4-space, and "\t" gives tab indent - exactly what this tool does behind the scenes.
Tips for Debugging JSON
A few practical habits that save time when working with JSON regularly:
Validate before debugging logic. If an API response is not parsing correctly, run it through this formatter first. Many "bugs" turn out to be a single missing comma or an extra trailing comma in the response.
Use the tree view for nested data. API responses from services like Stripe, Twilio, or AWS often have 4-5 levels of nesting. Scrolling through hundreds of formatted lines is slow. The tree view lets you collapse sections you do not care about and focus on the specific nested object you need.
Check your encoding. If you see \uXXXX escape sequences in your JSON, those are Unicode code points. They are valid JSON and will decode correctly when parsed. You do not need to manually convert them - JSON.parse() handles them automatically.
Watch for number precision. JSON numbers are parsed as IEEE 754 doubles in JavaScript, which means integers larger than 2^53 - 1 (9,007,199,254,740,991) will lose precision. APIs that return large IDs (like Twitter/X snowflake IDs) often send them as strings for this reason.
To convert JSON to other formats, the JSON to CSV Converter handles tabular data, and the YAML to JSON Converter translates between config formats. For viewing JSON structure visually, the JSON Tree Viewer renders a collapsible tree. If you need to inspect encoded payloads, the JWT Decoder can parse Base64-encoded JSON tokens.
All processing happens entirely in your browser using the native JSON.parse() and JSON.stringify() functions. Your data is never sent to any server.
Sources
- IETF RFC 8259 - The JavaScript Object Notation (JSON) Data Interchange Format
- ECMA-404 - The JSON Data Interchange Syntax (2nd edition)
- MDN - JSON object (parse, stringify)
- Introducing JSON (json.org)
- IETF RFC 3339 - Date and Time on the Internet
- ECMA-262 - The JSON Object (IEEE 754 number handling)
Frequently Asked Questions
What is JSON formatting and why does it matter?
JSON formatting (also called pretty-printing) adds consistent indentation and line breaks to compressed JSON data, making it human-readable. This is essential for debugging API responses, reviewing configuration files, and understanding data structures at a glance.
How does the JSON validator detect errors?
The tool uses the browser's native JSON parser to validate your input. When it encounters a syntax error such as a missing comma, unmatched bracket, or trailing comma, it reports the exact error message and location so you can quickly fix the problem.
What is the difference between formatting and minifying JSON?
Formatting adds whitespace and indentation for readability, while minifying removes all unnecessary whitespace to produce the smallest possible output. Minified JSON is ideal for network transmission and storage, while formatted JSON is better for development and debugging.
Can this tool handle large JSON files?
This tool processes JSON entirely in your browser with no server uploads. It can handle moderately large JSON documents (several megabytes) depending on your device's memory. For extremely large files, consider using a desktop application or command-line tool.
Related Tools
Link to this tool
Copy this HTML to link to this tool from your website or blog.
<a href="https://toolboxkit.io/tools/json-formatter/" title="JSON Formatter & Validator - Free Online Tool">Try JSON Formatter & Validator on ToolboxKit.io</a>