JSON (JavaScript Object Notation) is the default data format of the modern web. APIs return it, config files use it, databases store it. Despite being designed to be human-readable, raw JSON from a server or a database dump can look like a wall of unreadable text. Formatting it takes a second and makes it immediately clear.
What is JSON?
JSON is a text-based format for representing structured data. It supports six data types:
- Strings:
"hello"(always double-quoted) - Numbers:
42,3.14,-7 - Booleans:
true,false - Null:
null - Arrays:
[1, 2, 3] - Objects:
{"key": "value"}
A JSON document is always one of these types at the root. In practice, APIs almost always return an object or an array at the top level.
Formatted vs minified JSON
The same JSON data can be written in two ways.
Minified (compact):
{"user":{"id":1,"name":"Ana Petrović","active":true,"scores":[98,87,95]}}
Formatted (pretty-printed):
{
"user": {
"id": 1,
"name": "Ana Petrović",
"active": true,
"scores": [98, 87, 95]
}
}
Both represent exactly the same data. Whitespace (spaces, newlines, indentation) has no meaning in JSON — parsers ignore it. Minified JSON is smaller, which matters when transmitting data over a network. Formatted JSON is easier for humans to read and diff.
When you receive API data or copy JSON from a log, formatting it instantly reveals the structure.
Common JSON errors and how to fix them
JSON syntax is strict. A single mistake causes the entire document to be invalid. Here are the errors you'll encounter most often:
Trailing comma
{
"name": "Ana",
"city": "Podgorica", ← error: comma after the last item
}
JSON does not allow a comma after the last item in an object or array. JavaScript does (with a trailing comma in object literals), but JSON is stricter. Remove the trailing comma.
Single quotes instead of double quotes
{
'name': 'Ana' ← error: must use double quotes
}
JSON requires double quotes for strings and keys. Single quotes are not valid.
Unquoted keys
{
name: "Ana" ← error: keys must be quoted
}
In JavaScript object literals, you can write { name: "Ana" }. In JSON, keys must always be strings in double quotes: { "name": "Ana" }.
Missing comma between items
{
"name": "Ana"
"city": "Podgorica" ← error: missing comma after previous item
}
Every pair in an object and every value in an array must be separated by a comma (except the last one).
Unescaped special characters in strings
{
"note": "She said "hello" to me" ← error: unescaped quotes
}
Double quotes inside a string must be escaped with a backslash: "She said \"hello\" to me". Other characters that need escaping: \\ (backslash), \/ (forward slash, optional), \n (newline), \t (tab), \r (carriage return).
Comments
{
// This is my config ← error: comments are not allowed in JSON
"timeout": 30
}
Standard JSON does not support comments. If you need a config format with comments, look at JSONC (JSON with Comments, used by VS Code) or YAML. When working with pure JSON, remove any comments before validating or parsing.
How to format JSON in your browser
The fastest way to format, validate, and minify JSON without installing anything is to use Toolmingo's JSON Formatter. Paste your JSON, click Format, and you get:
- Indented output that's easy to read
- Validation that highlights the exact line and character of any syntax error
- Minify option to strip whitespace when you need compact output
Everything runs in your browser. Your data is never sent to a server.
How to format JSON in code
If you need to format JSON programmatically:
JavaScript:
const formatted = JSON.stringify(data, null, 2); // 2-space indent
const minified = JSON.stringify(data);
Python:
import json
formatted = json.dumps(data, indent=2)
minified = json.dumps(data, separators=(',', ':'))
Command line (using jq):
cat data.json | jq . # pretty-print
cat data.json | jq -c . # compact/minified
curl + jq together:
curl -s https://api.example.com/data | jq .
Working with large JSON files
For JSON files too large to open in a text editor:
- Use
jqon the command line — it handles gigabyte-sized files efficiently - Use a streaming parser in your language (Python's
ijson, Node'sJSONStream) - In the browser, paste only the section you need to inspect
The JSON Formatter tool is ideal for moderate-sized JSON (API responses, config files, log entries). For files in the hundreds of megabytes, a command-line tool will be faster.
JSON vs JSONL
You may encounter files with the .jsonl extension — JSON Lines. Each line is a separate, valid JSON document (typically an object). This format is common for log files and machine learning datasets because you can stream it line by line without loading the entire file into memory.
{"id": 1, "name": "Ana"}
{"id": 2, "name": "Marko"}
{"id": 3, "name": "Ivana"}
JSONL files are not valid JSON as a whole, so a standard JSON formatter won't handle them. To work with JSONL, process it line by line.
FAQ
Q: What's the difference between JSON and JavaScript objects?
They look similar but aren't the same. JSON is a text format with a strict specification. A JavaScript object is a runtime data structure. Keys in JSON must be strings; JavaScript object keys can be symbols or unquoted identifiers. JSON doesn't support functions, undefined, Date objects, or comments. When you call JSON.stringify(), JavaScript converts an object to a JSON string; JSON.parse() goes the other way.
Q: Why does JSON use double quotes instead of single quotes? The JSON specification (RFC 8259) requires double quotes. JSON was derived from a subset of JavaScript syntax, and the designers chose double quotes as the canonical form. There is no technical reason single quotes can't represent strings, but the spec is explicit.
Q: Is formatted JSON slower to parse? The difference is negligible for any modern parser. Parsers discard whitespace as they go. If you're squeezing out milliseconds in a performance-critical path, minifying helps slightly — but formatting vs. minifying is not a meaningful optimization for most applications.
Q: Can JSON represent dates?
Not natively. JSON has no date type. The common convention is to serialize dates as ISO 8601 strings like "2026-07-12T14:30:00Z", and parse them on the receiving end. Some systems use Unix timestamps (a number of seconds or milliseconds since epoch) instead.