JSON Formatter
Beautify and minify JSON
About This Calculator
JSON (JavaScript Object Notation) is the dominant data interchange format for web APIs, configuration files, and data storage. JSON formatting (pretty-printing) adds indentation and newlines for human readability; minification removes whitespace to reduce file size for transmission. Both represent the same data structure.
Formula
Valid JSON: double-quoted keys, no trailing commas, no comments
Data types: string, number, boolean (true/false), null, array [], object {}
Minify: remove all whitespace outside strings
Pretty-print: add 2 or 4-space indentation per nesting level
Example Calculation
Beautify the minified JSON: {"name":"Alice","age":30,"active":true}
- Parse the JSON string into a data structure
- Re-serialize with 2-space indentation
- Output with each key-value on its own line
{
"name": "Alice",
"age": 30,
"active": true
}
JSON Data Types
| Type | Example | Notes |
|---|---|---|
| String | "hello" | Must use double quotes (not single) |
| Number | 42 or 3.14 | No quotes; int or float |
| Boolean | true or false | Lowercase only |
| Null | null | Lowercase |
| Array | [1, 2, 3] | Ordered list |
| Object | {"key": "val"} | Unordered key-value pairs |
Frequently Asked Questions
What is the difference between JSON and JavaScript objects?
JSON is a text format (a string). JavaScript objects are in-memory data structures. JSON has stricter syntax: keys must be double-quoted strings, no trailing commas, no comments, and no undefined or function values. Use JSON.parse() to convert JSON text to a JS object and JSON.stringify() to convert back.
Why minify JSON?
Minification removes all whitespace (spaces, newlines, indentation) that is not inside string values. This reduces file size by 30-50%, which matters for API responses, especially on mobile connections. The data is identical — parsers don't care about whitespace.
Can JSON have comments?
No. Standard JSON does not support comments. This is intentional — JSON is a data format, not a config format. Workarounds: use a key like '__comment' (not ideal), use JSONC (JSON with Comments) for config files (VS Code settings use it), or use YAML or TOML for heavily commented configs.
What is JSON Schema?
JSON Schema is a vocabulary for validating and annotating JSON documents. It defines the expected structure, data types, required fields, and value constraints. It is used for API documentation (OpenAPI), form validation, and configuration validation. Tools like ajv (JavaScript) or jsonschema (Python) validate JSON against schemas.