JSON Formatter
Format, beautify, and minify your JSON data instantly in your browser.
Features
- VS Code Monaco Editor Experience: Enjoy rich syntax highlighting, bracket matching, line numbers, and folding just like in Visual Studio Code.
- Instant Beautify & Pretty-Print: Format compact or messy JSON strings into clean 2-space indented hierarchical structures with a single click.
- Zero-Overhead Minification: Strip all redundant whitespace, line breaks, and indentation to produce the smallest possible payload for production APIs.
- 100% Client-Side Privacy: Parsing and formatting run purely inside your local browser via native
JSON.parse()andJSON.stringify(). Zero data transmission. - Instant Syntax Error Diagnosis: Real-time red squiggly underlines and error messages highlighting the exact line and column of malformed characters.
- Developer Ecosystem: Directly connected to our JSON Validator, JSON ↔ YAML, and JSON ↔ CSV converters.
How it works
This online JSON beautifier parses your JSON string using JavaScript's native engine, formats it into a standardized 2-space indented layout, and highlights syntax structures. You can also click Minify to collapse the entire structure into a single compact line for network transmission.
- Paste or type your raw JSON into the editor.
- Click Format to pretty-print or Minify to remove whitespace.
- Copy the clean output to your clipboard or download it as a
.jsonfile. If syntax errors appear, navigate to our JSON Validator for detailed line inspection.
JSON Data Types & Syntax Rules (RFC 8259)
JSON (JavaScript Object Notation) is a lightweight, language-independent data interchange format. RFC 8259 defines the standard syntax:
| Data Type | Syntax Example | Rules & Limitations |
|---|---|---|
| String | "name": "Alice 🚀" | Must use double quotes ("). Single quotes (') are strictly invalid. Backslashes must be escaped (\\). |
| Number | "price": 42.99, "exp": 1e6 | Supports integers, floating points, and scientific E-notation. Leading zeros, NaN, and Infinity are illegal. |
| Object | { "id": 1, "active": true } | Unordered collection of key-value pairs enclosed in braces. All keys must be double-quoted strings. |
| Array | "tags": ["dev", "tools"] | Ordered sequence of values enclosed in square brackets. Trailing commas (e.g. [1, 2,]) are strictly forbidden. |
| Boolean | "verified": true | Must be lowercase literals: true or false. Titlecase (True) is invalid. |
| Null | "deletedAt": null | Represents an empty or non-existent value. undefined does not exist in JSON. |
How to Format & Minify JSON in Code
Common implementations for pretty-printing and compressing JSON across backend frameworks and scripts:
JavaScript / TypeScript (Browser & Node.js)
const data = { user: "Alice", role: "admin", scores: [98, 85] };
// Pretty-print with 2-space indentation
const formatted = JSON.stringify(data, null, 2);
// Minify (compact representation)
const minified = JSON.stringify(data);Python 3
import json
data = {"user": "Alice", "role": "admin", "scores": [98, 85]}
# Pretty-print with 2 spaces
formatted = json.dumps(data, indent=2)
# Minify for network transport
minified = json.dumps(data, separators=(',', ':'))Go (Golang)
package main
import (
"encoding/json"
"fmt"
)
func main() {
data := map[string]interface{}{"user": "Alice", "role": "admin"}
// Pretty-print with 2-space indentation
formatted, _ := json.MarshalIndent(data, "", " ")
fmt.Println(string(formatted))
// Minify
minified, _ := json.Marshal(data)
fmt.Println(string(minified))
}Command Line / Terminal (Linux & macOS)
# Using 'jq' (recommended) cat payload.json | jq . # Using Python's built-in tool (no dependencies required) python3 -m json.tool payload.json
Related JSON Tools & Tutorials
JSON Validator
Validate syntax and catch exact line and column numbers of trailing commas and missing quotes.
JSON Error Library
Test 20 real-world malformed JSON examples with one-click corrections.
JSON ↔ YAML Converter
Convert JSON payloads directly to human-friendly YAML for Kubernetes and Docker configurations.
JSON ↔ CSV Converter
Convert JSON arrays to flat CSV tables or parse spreadsheet CSV files back to JSON.
How to Fix Invalid JSON
Complete troubleshooting manual with corrected code snippets for the top 10 syntax errors.
What is JSON?
A complete deep-dive into JSON origin, serialization, parsing, and security best practices.
Frequently Asked Questions
Does my JSON data leave my device?
No, never. The entire formatting, beautification, and minification pipeline executes locally on your machine using your browser's native JavaScript runtime. We do not transmit, log, or store your JSON payloads on any remote server.
Why does standard JSON not support comments (// or /* */)?
Douglas Crockford, the creator of JSON, intentionally omitted comments to prevent people from using them to hold parsing directives or metadata (which caused interoperability issues in early XML). If you need comments in configurations, consider JSONC (JSON with Comments) or convert your payload to YAML using our JSON to YAML converter.
What is the difference between JSON pretty-printing and minification?
Pretty-printing adds human-readable indentation (typically 2 or 4 spaces) and newlines to make nested data structures easy to inspect. Minification strips out all non-essential whitespace and line breaks, reducing payload byte size by 20% to 50% for high-throughput network transmission.
How do I format JSON in the command line (Terminal)?
On Linux and macOS, you can use 'jq .' (e.g., cat data.json | jq .) or Python's built-in module: python3 -m json.tool data.json. Both tools validate and pretty-print JSON files instantly.
What data types are allowed in valid JSON (RFC 8259)?
Standard JSON supports exactly six data types: String (enclosed in double quotes), Number (integer or floating point), Object (key-value pairs in braces {}), Array (ordered list in brackets []), Boolean (true or false), and null. Undefined, functions, and NaN are not permitted.
How do I fix common 'Unexpected token' or 'Invalid JSON' errors?
Common mistakes include trailing commas after the final element in an array or object, using single quotes (') instead of standard double quotes ("), unquoted object keys, or unescaped backslashes and double quotes inside string values.