“API responses come back as one unreadable line” or “my config JSON keeps throwing errors” - these are moments when JSON formatting comes to the rescue.
In this article, we explain how to format JSON: the difference between pretty-printing and minifying, common syntax errors and how to fix them, and how to validate JSON in your browser.
What is JSON?
JSON (JavaScript Object Notation) is a standard text format for data. It powers web APIs and application config files everywhere, standardized in RFC 8259.
{"name":"Taro","age":30,"address":{"city":"Tokyo","zip":"100-0001"}}
The line above is valid JSON, but hard to read. Pretty-printing makes it look like this:
{
"name": "Taro",
"age": 30,
"address": {
"city": "Tokyo",
"zip": "100-0001"
}
}
Key point: Pretty-printing and minifying only change the appearance, never the data. Minify when sending or storing, pretty-print when reading or editing.
Common JSON errors and fixes
JSON is strict, and tiny mistakes break parsing. The most common errors:
| Error | Example | Fix |
|---|---|---|
| Trailing comma | [1, 2, 3,] |
No comma after the last item |
| Single quotes | {'name': 'Taro'} |
JSON strings use double quotes |
| Comments | // note |
JSON has no comments (remove them) |
| Unquoted keys | {name: "Taro"} |
Keys must be double-quoted |
| Unquoted strings | {"age": 30 years} |
Strings must be double-quoted |
Example: finding the error
What is wrong with this JSON?
{
"name": "Taro",
"age": 30,
"hobbies": ["reading", "walking",],
}
Two problems:
- A trailing comma in the array (
"walking",) - A trailing comma after the object (
},)
Correct version:
{
"name": "Taro",
"age": 30,
"hobbies": ["reading", "walking"]
}
Caution: Unlike JavaScript objects, JSON does not allow single quotes, comments or trailing commas. Always validate pasted code with a JSON validator.
How to format JSON
With the Tools Hub JSON formatter, paste your JSON and format, minify or validate instantly.
Paste your JSON
Paste an API response or config file into the input area.
Pick format, minify or validate
Pretty-print for readability, minify to save bytes, or just check the syntax.
Copy the result
Copy or download the formatted JSON. If there is an error, it is shown with details.
The tool introduced in this article
JSON Formatter
Format, minify and validate. All in your browser - your data is never uploaded.
JSON data types you will meet
JSON supports a small set of data types. Knowing them makes errors much easier to spot:
| Type | Example | Notes |
|---|---|---|
| String | "name": "Taro" |
Must be in double quotes |
| Number | "age": 30 |
No quotes, no thousand separators |
| Boolean | "paid": true |
true or false only |
| Array | "tags": ["a", "b"] |
Comma-separated list |
| Object | "address": { "city": "Tokyo" } |
Nested key-value pairs |
| Null | "note": null |
A deliberate empty value |
A common beginner mistake is wrapping numbers in quotes ("age": "30"). It parses fine, but the value becomes a string instead of a number - which can break calculations downstream. Validation catches the syntax errors, but only you can decide whether the types match your needs.
Formatting tips
- Japanese text: UTF-8 JSON formats fine as-is. If you see garbled characters, align the file encoding to UTF-8
- Line endings: Windows (CRLF) and macOS (LF) differ. Formatters usually handle this automatically
- Large JSON: Processing depends on browser memory, but typical API responses are no problem
Summary
- JSON is the standardized data format defined in RFC 8259
- Pretty-print for reading, minify for size - the data stays the same
- Trailing commas, single quotes and comments are the main error sources
- JSON supports strings, numbers, booleans, arrays, objects and null
- Validation pinpoints where errors are
- The Tools Hub formatter works entirely in your browser - nothing is uploaded
Next time you need to format JSON, use the steps above or the Tools Hub JSON formatter.
FAQ
How do I pretty-print JSON nicely?
Paste it into the JSON formatter and press “Format”. It is displayed with clean indentation.
How do I find JSON errors?
Use the “Validate” feature - it reports where and what the problem is. Trailing commas and single quotes are the usual culprits.
What is the difference between minify and format?
Format adds indentation for readability; minify strips whitespace to shrink the data. Neither changes the data itself.
Can I format JSON containing Japanese text?
Yes. UTF-8 Japanese text formats without issue. If it appears garbled, check the encoding of your input.