What Is a JSON Formatter?
A JSON formatter (also called a JSON beautifier or JSON pretty printer) is a tool that takes raw, compressed, or poorly indented JSON text and reformats it into a clean, human-readable structure with consistent indentation, line breaks, and spacing. It also validates the JSON against the ECMA-404 standard, catching syntax errors before they reach your application.
JSON (JavaScript Object Notation) is the universal data interchange format of the modern web. It powers REST APIs, configuration files, database documents, event payloads, and inter-service communication. When you receive a minified API response or a single-line configuration blob, a formatter makes it immediately readable and debuggable.
JSON Syntax Rules — What the Validator Checks
Valid JSON must follow strict rules defined in RFC 8259 and ECMA-404. Our validator checks all of them:
- →String quoting: All keys and string values must be wrapped in double quotes. Single quotes are not valid JSON.
- →Trailing commas: JSON does not allow trailing commas after the last element in an object or array. This is the most common source of parse errors.
- →Data types: Valid JSON values are strings, numbers, booleans (
true/false),null, objects, and arrays.undefinedand functions are not valid. - →Comments: JSON does not support comments.
// commentor/* comment */will cause a parse error. - →Escape sequences: Special characters in strings must be escaped:
\",\\,\/,\n,\r,\t,\uXXXX. - →Number format: Numbers cannot have leading zeros (except
0.x). Infinity and NaN are not valid JSON numbers.
JSON Formatting vs. JSON Minification
This tool supports both operations:
Formatting (Beautify)
Formatting expands compressed JSON into a readable multi-line structure with configurable indentation (2 spaces, 4 spaces, or tabs). Use this when debugging API responses, reviewing configuration files, or reading data from a database. Formatted JSON is significantly easier to diff in version control and review in pull requests.
Minification (Compress)
Minification removes all whitespace, newlines, and indentation, producing the smallest possible valid JSON string. Use this before embedding JSON in HTTP responses, storing in databases, or transmitting over the wire. A minified JSON payload can be 20–40% smaller than its formatted equivalent, directly reducing bandwidth and improving API response times.
Choosing Indentation
The tool supports 2-space, 4-space, and tab indentation. Two spaces is the most common convention in JavaScript and Node.js projects. Four spaces is standard in Python. Tabs are preferred in some Go and Rust codebases. The choice is purely cosmetic — all produce semantically identical JSON.
Common JSON Errors and How to Fix Them
SyntaxError: Unexpected token
This is the most common JSON error. It usually means a missing or extra comma, an unquoted key, or a single-quoted string. Paste your JSON into the formatter — the error message will point to the exact position of the problem.
Trailing Comma After Last Property
JavaScript allows trailing commas in object and array literals, but JSON does not. If you copy a JS object literal into a JSON context, remove the trailing comma after the last property. Example: {"key": "value",} is invalid JSON — remove the comma before the closing brace.
Unescaped Special Characters
If your string values contain double quotes, backslashes, or control characters, they must be escaped. A string like "path": "C:\Users\name" is invalid — it should be "path": "C:\\Users\\name".
NaN, Infinity, or undefined Values
JavaScript's JSON.stringify() silently drops undefined values and converts NaN and Infinity to null. If you see unexpected null values in your JSON output, check your source data for these JavaScript-specific values.
JSON in Modern Development Workflows
JSON is everywhere in modern software development. Here are the most common contexts where a formatter and validator saves time:
- →REST API debugging: Paste raw API responses to inspect structure, find missing fields, and verify data types before writing parsing code.
- →Configuration files:
package.json,tsconfig.json,appsettings.json— validate before committing to avoid breaking CI/CD pipelines. - →Database documents: MongoDB, DynamoDB, and Firestore store data as JSON documents. Format query results for readability.
- →Webhook payloads: Inspect incoming webhook data from Stripe, GitHub, Slack, and other services to understand the payload structure.
- →JWT inspection: JWT tokens contain Base64-encoded JSON payloads. Use our JWT Decoder to inspect token claims without leaving the browser.
JSON vs. JSON5 vs. JSONC
JSON5 is a superset of JSON that allows comments, trailing commas, single-quoted strings, and unquoted keys. It is used in some configuration files (like .eslintrc) but is not valid standard JSON.
JSONC (JSON with Comments) is used by VS Code for its configuration files. It looks like JSON but supports // line comments and /* block comments */. It is also not valid standard JSON.
This formatter validates against the strict RFC 8259 standard. If you are working with JSON5 or JSONC, you will need to remove comments and trailing commas before validating here.
JSON in Every Language
Every major programming language has built-in JSON support:
- →JavaScript:
JSON.parse(str)/JSON.stringify(obj, null, 2) - →Python:
import json; json.loads(str)/json.dumps(obj, indent=2) - →Go:
encoding/jsonstdlib —json.Unmarshal/json.MarshalIndent - →PHP:
json_decode($str)/json_encode($obj, JSON_PRETTY_PRINT) - →Java: Jackson or Gson libraries —
objectMapper.readValue()/objectMapper.writerWithDefaultPrettyPrinter() - →C#:
System.Text.Jsonor Newtonsoft.Json —JsonSerializer.Deserialize<T>() - →Rust:
serde_jsoncrate —serde_json::from_str()/serde_json::to_string_pretty()
Try JSON parsing and serialization live in the Developer Lab — supports 25+ languages with zero setup.
Privacy and Security
All JSON formatting and validation happens entirely in your browser using JavaScript's native JSON.parse() and JSON.stringify() APIs. Your data never leaves your device — nothing is sent to any server.
This is especially important when working with sensitive data: API keys, authentication tokens, personal information, or proprietary business data. You can safely format production JSON payloads without any risk of data exposure. If your JSON contains authentication tokens, also check our JWT Decoder to inspect token claims directly.