How to Format, Minify and Validate JSON
Updated · 3 min read
Short answer
Paste your JSON into the JSON Formatter & Validator, choose Format to indent it or Minify to compress it, and read the line and column it reports if the data is invalid. Most errors come from a handful of small syntax slips.
Formatting, minifying and validating: what each does
JSON is plain text, so the same data can be written in many ways. Formatting (also called pretty-printing) adds line breaks and indentation so a person can follow the nesting. Minifying removes every space and line break that is not inside a string, so the file is as small as it can be. Validating checks that the text follows the JSON grammar, which is stricter than JavaScript object syntax.
| Mode | What changes | Use it when |
|---|---|---|
| Format | Adds indentation and line breaks | You are reading, debugging or reviewing data |
| Minify | Removes unneeded whitespace | You are sending data over the network or storing it compactly |
| Validate | Checks the syntax, changes nothing | A parser rejects your data and you need to know why |
Format JSON step by step
- Open the JSON Formatter & Validator and paste your text into the input box.
- Choose Format to get indented output, or Minify for the compact form.
- If the text is invalid, read the message. It points to the line and column where the parser gave up.
- Fix that spot, run it again, and repeat until the output appears.
- Copy the result back into your editor, request body or config file.
The five mistakes behind most JSON errors
- A trailing comma after the last item in an object or array. JSON does not allow it, even though many programming languages do.
- Single quotes. Strings and property names must use double quotes.
- Unquoted property names. `{name: 1}` works in JavaScript, but JSON needs `{"name": 1}`.
- Comments. JSON has no comment syntax, so `//` and `/* */` make the text invalid.
- Unescaped characters inside strings, such as a raw line break or a stray backslash. Use `\n` for a new line and `\\` for a backslash.
Reading an error location
A parser reports the point where the text stopped making sense, which is often just after the real mistake. If the error says line 12, look at the end of line 11 as well: a missing comma or a missing closing bracket is usually found there. A message about an unexpected end of data almost always means a bracket or brace was never closed.
Related encoding tasks
JSON often travels inside other formats. If a value arrives as an opaque string of letters and digits ending in equals signs, it may be Base64, which the Base64 Encoder & Decoder can unpack before you format it. If JSON is part of a web address or query string, it will be percent-encoded, and the URL Encoder & Decoder restores the readable text.
Dates inside JSON are often Unix timestamps. Our guide What Is a Unix Timestamp? explains how to read them, and the broader roundup Best Free Online Developer Tools lists the other utilities that help with everyday debugging.
A note on sensitive data
Only paste data you are comfortable handling in a browser tab. For API keys, tokens or customer records, check how any online tool processes your input first, or format the data locally in your own editor.
Choosing between two and four spaces
Indentation width is a matter of taste and team convention. Two spaces keep deeply nested data narrow enough to fit on screen, while four spaces make each level easier to spot. The data means exactly the same either way, because JSON ignores whitespace outside strings, so pick the style your project already uses and stay consistent.
A before and after example
Minified text such as {"id":7,"tags":["a","b"],"active":true} is valid but hard to scan. Formatted, the same data puts each property on its own line with the array items indented beneath it. Nothing about the values changes: strings, numbers, true, false, null, arrays and objects are the only types JSON has, and the formatter simply lays them out for you.
Tools in this guide
JSON Formatter & Validator
Format, minify and validate JSON, with the line and column of any error.
Developer
Base64 Encoder & Decoder
Encode text to Base64 or decode it back, with correct UTF-8 handling and a URL-safe option.
Developer
URL Encoder & Decoder
Percent-encode or decode URLs and query values, and list the key/value pairs of any query string.
Developer
Unix Timestamp Converter
Convert Unix timestamps to readable dates and dates back to timestamps, in UTC and your time zone.
Developer