The JSON Formatter is a free browser-based tool that formats, validates, and minifies JSON data instantly without sending your content to any server. It uses the browser's native JSON.parse() and JSON.stringify() functions, supports 2-space and 4-space indentation, detects syntax errors with exact line and column positions, and can sort keys alphabetically or find duplicate keys.
JSON Formatter & Validator
How it works
Last updated: November 2026
This tool uses the browser's built-in JSON.parse() to parse your input, then JSON.stringify() to re-serialize it with your chosen indentation. Because it relies on the native JSON parser, it correctly handles all valid JSON including nested objects, arrays, strings with escape sequences, numbers, booleans, and null.
Beautify adds whitespace and line breaks so the structure is easy to read. Minify does the opposite — it removes all unnecessary whitespace to produce the smallest possible output, useful when transmitting JSON over a network. Sort Keys recursively alphabetises all object keys before beautifying. Validate checks whether your input is syntactically correct JSON and reports the exact error with line and column number.
All processing runs entirely in your browser. No data is sent to any server.
JSON Specification
JSON (JavaScript Object Notation) is defined by RFC 8259 (December 2017), which supersedes RFC 7159 and RFC 4627. The canonical grammar is also described at json.org.
Valid value types
- object — unordered set of key/value pairs:
{"key": "value"} - array — ordered list of values:
[1, 2, 3] - string — double-quoted Unicode:
"hello" - number — integer or floating point, no leading zeros:
42,3.14,-1e10 - boolean —
trueorfalse - null —
null
Common spec violations
- Trailing commas —
{"a":1,}is invalid - Single-quoted strings —
{'key': 'value'}is invalid; use double quotes - Unquoted keys —
{key: "value"}is invalid - Comments — JSON has no comment syntax;
// ...and/* ... */are invalid - NaN / Infinity — not valid JSON number values
- Leading zeros —
007is invalid as a number literal
For extended JSON with comments and trailing commas, see JSON5. For schema-based validation, see JSON Schema.
Tips & Tricks
Sort keys before committing
Running Sort Keys before committing JSON config files makes git diffs show only genuine value changes — not accidental key reorderings from different editors or serialisers.
Use Tree view for deeply nested JSON
The Tree view uses virtual rendering — only visible rows are in the DOM — so it handles JSON with thousands of keys smoothly. Click any folder node to collapse entire subtrees.
Load JSON from a URL directly
Use the URL button to fetch and format a live JSON endpoint. If CORS blocks the direct request, the tool automatically retries via a proxy — the notice bar tells you which path was used.
Duplicate keys are silent killers
JSON.parse() silently discards all but the last value for duplicate keys. Find Duplicates surfaces them before they cause hard-to-trace bugs — especially common when merging JSON objects programmatically.
Tabs use separate output state
Each tab stores its own output and view (Text vs Tree) independently. Switching tabs never modifies the input — paste different JSON into each tab without them interfering.
Rename tabs to track context
Double-click any tab name to rename it. Useful when comparing multiple related JSON payloads — e.g. "Request", "Response", "Expected" — without losing context between sessions (tabs are persisted in localStorage).
Code Examples
Node.js
const fs = require('fs');
const raw = fs.readFileSync('data.json', 'utf8');
const parsed = JSON.parse(raw);
const formatted = JSON.stringify(parsed, null, 2);
fs.writeFileSync('data-formatted.json', formatted);
console.log('Formatted:', formatted); Python
import json
with open('data.json') as f:
data = json.load(f)
# Pretty-print with 2-space indent
formatted = json.dumps(data, indent=2)
print(formatted)
# Minify
minified = json.dumps(data, separators=(',', ':'))
print(minified) CLI
# Format with python (available everywhere) python3 -m json.tool data.json # Format with jq (install: brew install jq) jq . data.json # Minify with jq jq -c . data.json # Sort keys with jq jq -S . data.json # Validate only (exit code 0 = valid) jq empty data.json && echo "Valid JSON"
Frequently Asked Questions
- What does JSON stand for?
- JSON stands for JavaScript Object Notation. It was specified by Douglas Crockford in the early 2000s and is now defined by RFC 8259 (also published as ECMA-404). Despite the name, JSON is language-independent — the "JavaScript" refers only to its origins in JS object literal syntax, not to any runtime dependency. JSON encodes data as six types: objects (key-value pairs), arrays, strings, numbers, booleans, and null. It was designed to be a minimal, human-readable serialization format that maps directly to native data structures in virtually every programming language. JSON has largely replaced XML for web APIs because its syntax is simpler and its parsers are significantly faster. Every major language includes built-in JSON support: JSON.parse() in JavaScript, json.loads() in Python, and Gson or Jackson in Java.
- What is JSON used for?
- JSON is used to transmit structured data between a server and a web application, as a configuration file format, and as a data storage format. REST APIs almost universally return JSON responses. Common examples include
package.jsonin Node.js projects, API responses from services like GitHub, Stripe, and AWS, and browser localStorage data. JSON is also used as the basis for configuration formats like tsconfig.json, .prettierrc, and .eslintrc. Document databases such as MongoDB and Firestore store records as JSON-like documents natively. JSON's simplicity — no schema required, human-readable, universally supported — makes it the default choice for any new API or configuration format where XML would have been used in the past. - What is a JSON formatter?
- A JSON formatter (also called a JSON beautifier or JSON pretty printer) takes compact or minified JSON text and adds indentation and line breaks to make it human-readable. It uses
JSON.parse()to validate the input, thenJSON.stringify()with an indent argument to re-serialize it with consistent formatting. For example, the compact string{"name":"Alice","age":30}becomes a multi-line block with each key on its own indented line, making nested structures easy to scan. Formatters are essential when debugging API responses, reading log files, or reviewing JSON configuration. Some formatters — including this one — also offer syntax highlighting, Tree view navigation, key sorting, and duplicate key detection as additional features. - Is my JSON data sent to a server?
- No. All formatting, validation, and transformation happens entirely in your browser using JavaScript. Your data never leaves your machine and no account or sign-up is required. This matters when working with sensitive payloads such as API tokens, personally identifiable information (PII), or internal schema structures you do not want transmitted over the internet. The tool uses the browser's native JSON.parse() and JSON.stringify() functions, which run entirely in the JavaScript engine — no WebSocket connections, no analytics on your input data, and no server-side processing of any kind. You can verify this by checking the browser's Network panel while using the formatter.
- What is the difference between formatting and minifying JSON?
- Formatting (beautifying) adds whitespace, indentation, and newlines so the structure is easy for humans to read and edit. Minifying removes all unnecessary whitespace to produce the smallest possible byte size. Minified JSON is used in production for network transfer; formatted JSON is used during development and debugging. For example, a 10 KB formatted JSON response might shrink to 6 KB when minified — a meaningful saving when sent in every API response. In Node.js, JSON.stringify(data, null, 2) produces 2-space indented output; JSON.stringify(data) with no third argument produces minified output. In Python, json.dumps(data, indent=2) formats and json.dumps(data, separators=(',', ':')) minifies. Many build tools such as webpack and Vite automatically minify JSON assets during the production bundle step.
- Why is my JSON invalid?
- The most common JSON syntax errors are: trailing commas after the last item (
{"a":1,}is invalid), single-quoted strings (JSON requires double quotes), unquoted keys ({key: "value"}is invalid), comments (// ...and/* ... */are illegal), and NaN or Infinity values. This formatter reports the exact line and column of the error. These restrictions are intentional — the JSON specification (RFC 8259) deliberately excludes features that complicate parsing and slow down parsers. If you need comments or trailing commas, use JSON5 (json5.org) or JSONC (VS Code's format), which are supersets of JSON with dedicated parsers. Use the dedicated JSON Validator or JSON Lint tool to check syntax without reformatting your input. - How do I sort JSON keys alphabetically?
- Use Sort Keys in the Tools dropdown. It recursively alphabetises all object keys at every nesting level before formatting. Sorting keys before committing JSON files reduces noisy git diffs — when keys are always in alphabetical order, only genuine value changes appear in diffs rather than accidental reorderings caused by different editors or serializers. For example, if one developer's code serializes an object as {"z":1,"a":2} and another's produces {"a":2,"z":1}, a git diff will show all keys as changed even though the data is identical. After sorting, both representations become {"a":2,"z":1} and no spurious diff appears. In Node.js, you can replicate this with JSON.stringify(obj, Object.keys(obj).sort(), 2), though a recursive sort is needed for nested objects.
- Can I convert JSON to YAML?
- Yes. The YAML Formatter can convert JSON to YAML in one click using the Convert to YAML option. YAML is a superset of JSON, so every valid JSON document is also valid YAML — but the converter produces idiomatic block-style YAML with proper indentation rather than the JSON flow-style braces. For example, {"name":"Alice","active":true} becomes a two-line block mapping. You can also use the dedicated JSON to YAML converter for a single-purpose workflow. Programmatically, Node.js can convert with js-yaml: yaml.dump(JSON.parse(jsonString)) produces clean YAML output. In Python, import json and yaml, then yaml.dump(json.loads(jsonString), default_flow_style=False) produces block-style YAML.
- How do I handle large JSON files?
- The formatter handles files up to several megabytes without issues since all processing is in-browser. For very large files (10 MB+), use the Upload button rather than pasting to avoid browser textarea performance limits. The Tree view is especially useful for navigating large nested JSON — it uses virtual rendering so only visible rows are in the DOM, allowing smooth navigation of thousands of keys. For programmatic handling of very large JSON files (100 MB+), consider streaming parsers such as node.js's stream-json library, which parses JSON token-by-token without loading the entire document into memory. Python's ijson library provides the same capability via an event-driven API, similar to SAX parsing for XML. Browser-based tools are best suited for files under 20 MB.
- What are duplicate keys in JSON?
- Duplicate keys occur when a JSON object has the same key name more than once at the same level — for example
{"id": 1, "id": 2}. RFC 8259 says duplicate keys SHOULD NOT appear, but does not forbid them, so the behavior is undefined and parser-dependent. Most parsers silently keep the last value, discarding earlier ones — meaning {"id":1,"id":2} typically resolves to {"id":2} with no warning. This commonly causes bugs when merging JSON objects programmatically or when different code paths produce the same key. The Python json module raises no error on duplicate keys; JavaScript's JSON.parse() also silently keeps the last value. Use Find Duplicates in the Tools dropdown to surface all duplicate keys and their paths before they cause hard-to-trace production bugs. - What is JSON Schema?
- JSON Schema is a vocabulary that describes the structure and constraints of JSON documents, defined at json-schema.org. A schema specifies which fields are required, their expected types, minimum and maximum numeric values, allowed string patterns, and enum values. Tools like Ajv (JavaScript) and jsonschema (Python) validate JSON data against a schema programmatically. JSON Schema is widely used in API documentation (OpenAPI/Swagger specs embed JSON Schema for request and response body definitions), form validation libraries, IDE autocomplete, and CI pipeline checks. The current stable version is JSON Schema Draft 2020-12. For quick schema-based validation, the JSON Formatter's Find Duplicates and Sort Keys features catch structural issues, while full JSON Schema validation requires a dedicated validator with an Ajv or similar backend.
- How do I minify JSON for production use?
- Click the Minify button to strip all whitespace, or use the standalone JSON Minifier tool. In Node.js,
JSON.stringify(data)with no third argument produces minified output. In Python,json.dumps(data, separators=(',', ':'))removes spaces after colons and commas. Minified JSON reduces payload size for API responses and static asset files. For HTTP APIs, additionally enable gzip or Brotli compression on the server — JSON compresses extremely well (often 70-80% size reduction) because of its repetitive key structure, so combining minification with compression gives the best results. CDN-hosted JSON files such as OpenAPI specs or GeoJSON datasets benefit most from both steps. Keep the unminified source committed to version control for readability. - What is the difference between JSON and JSON5?
- JSON5 is an unofficial extension of JSON that adds features for human-authored configuration files: single-quoted strings, trailing commas after the last item, single-line and block comments, unquoted keys that are valid JavaScript identifiers, and hexadecimal numeric literals. Standard JSON parsers such as JSON.parse() reject JSON5 syntax with a syntax error. JSON5 is used in some build tool configuration files and the Babel ecosystem; standard JSON is required for APIs, package.json, most IDE config files, and all inter-system data exchange. The json5 npm package provides a parser and stringifier. If you need comments specifically, consider JSONC (used by VS Code's tsconfig.json) instead of full JSON5, as JSONC is more widely supported by editors and linters.
- What is the difference between JSON and JSONC?
- JSONC (JSON with Comments) is a superset of JSON that allows
// single-lineand/* multi-line */comments. VS Code uses JSONC forsettings.jsonandtsconfig.json, and also allows trailing commas in some versions. Unlike JSON5, JSONC does not add unquoted keys, hexadecimal numbers, or single-quoted strings — it only extends standard JSON with comments and optionally trailing commas. Standard JSON parsers such as JSON.parse() reject JSONC and will throw a syntax error on the first comment character. VS Code uses its own built-in JSONC parser (available as the jsonc-parser npm package) to process these files. If you strip JSONC comments before parsing, the remaining content is valid standard JSON.
Related Tools
Other free developer tools available on DevFormatter.
YAML Formatter
Format, validate, and convert YAML. Detects YAML 1.1 coercion risks and expands anchors.
JSON Pretty Print
Instantly pretty-print and beautify compact or minified JSON with clean indentation.
XML Formatter
Format, validate, and convert XML to JSON. All processing runs in your browser.
JSON to YAML
Convert JSON to clean, readable block-style YAML instantly.
YAML to JSON
Convert YAML to formatted JSON. Anchors expanded, runs in your browser.
jq Playground
Run jq queries against JSON data instantly in your browser.
Base64 Encode / Decode
Encode text or binary data to Base64, or decode Base64 strings back to plain text.
URL Encode / Decode
Percent-encode URLs and query strings, or decode %XX sequences back to readable text.
JSON Validator
Check JSON syntax with exact line and column error positions. Runs entirely in your browser.
JSON Lint
Detect syntax errors in JSON with exact line and column positions and smart fix suggestions.
JSON Minifier
Strip all whitespace from JSON to reduce payload size for APIs and static assets.
JSON Diff
Compare two JSON objects side-by-side. See added, removed, and changed keys with full paths.
CSV to JSON
Convert CSV or TSV to a JSON array of objects. Auto-detects delimiter. Browser-only.