DevFormatter
JSON Formatter
 

JSON Formatter & Validator

How it works

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 — true or false
  • 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 — 007 is 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. Despite the name, JSON is language-independent and is used in virtually every programming language for data exchange.
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.json in Node.js projects, API responses from services like GitHub, Stripe, and AWS, and browser localStorage data.
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, then JSON.stringify() with an indent argument to re-serialize it with consistent formatting.
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.
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.
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.
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.
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.
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.
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. Most parsers silently keep the last value, discarding earlier ones. Use Find Duplicates to surface these before they cause silent bugs.
What is JSON Schema?
JSON Schema is a vocabulary that describes the structure and constraints of JSON documents. It specifies which fields are required, their expected types, min/max values, and allowed string patterns. Tools like Ajv (JavaScript) and jsonschema (Python) validate JSON data against a schema. JSON Schema is widely used in API documentation (OpenAPI/Swagger) and CI pipeline validation.
How do I minify JSON for production use?
Click the Minify button to strip all whitespace. 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.
What is the difference between JSON and JSON5?
JSON5 is an unofficial extension that adds features for human-authored config files: single-quoted strings, trailing commas, comments, unquoted identifier keys, and hexadecimal numbers. Standard JSON parsers reject JSON5 syntax. JSON5 is used in some build tool configs; standard JSON is used for APIs and most tooling.
What is the difference between JSON and JSONC?
JSONC (JSON with Comments) is a superset of JSON that allows // single-line and /* multi-line */ comments. VS Code uses JSONC for settings.json and tsconfig.json. Unlike JSON5, JSONC does not allow trailing commas or unquoted keys — it only adds comments. Standard JSON parsers reject JSONC.

Related Tools

Other free developer tools available on DevFormatter.