JavaScript / JSON Formatter
Beautify, minify, and validate JavaScript and JSON code
Sobre esta ferramenta
Paste any JavaScript or JSON and instantly beautify it with configurable indentation, minify it to the smallest possible size, or validate the syntax. Character and line count stats help you track code size. One-click copy makes it easy to use the result.
Como usar
- 1 Paste your JavaScript or JSON into the input area.
- 2 Select the Beautify tab to format with indentation, or Minify to compress.
- 3 Use the Validate tab to check for syntax errors.
- 4 Adjust the indent size in Beautify mode if needed.
- 5 Click Copy to copy the result to your clipboard.
Beautify, minify, validate: three jobs, one input
This tool does three distinct things to the same code. Beautify adds line breaks and indentation so a human can read the structure. Minify strips every byte that a machine does not need, shrinking the file for faster downloads. Validate checks whether the code is syntactically well-formed without running it. The key design decision behind all three is that they treat JSON and JavaScript differently, and understanding that split explains everything about the output you get.
How JSON and JavaScript are handled differently
When you paste text, the formatter first tries JSON.parse(). JSON is a strict, well-specified data format, so if your input is valid JSON, the tool can rebuild it perfectly: JSON.stringify(parsed, null, indent) for a beautified version, or JSON.stringify(parsed) with no spacing for the minified version. This round-trip is lossless and reliable.
If the text is not valid JSON — say it has function definitions, comments, or single-quoted strings — the parse fails and the tool falls back to a lightweight JavaScript formatter. That fallback is not a full parser. For beautifying, it walks the characters and re-indents based on braces, brackets, semicolons, and commas, while skipping over string contents so it does not break a literal like "a;b". For minifying, it uses regular expressions to remove /* */ and // comments, collapse runs of whitespace, and trim spaces around operators.
A worked example
Paste this compact object:
{"name":"Ada","langs":["JS","Py"],"active":true}
Because it is valid JSON, Beautify with a 2-space indent produces a structured tree with name, langs, and active each on their own indented line, and the array expanded one element per line. Switch to Minify and you get back the original single line with no extra spaces. Switch to Validate and you see "Valid JSON". Now add a JavaScript comment — // note — at the top, and the JSON parse fails, so Beautify switches to brace-based JS indentation and Validate reports "Valid JavaScript" instead.
What validation actually checks
The Validate tab first attempts JSON.parse(); if that succeeds you get "Valid JSON". Otherwise it passes your code to the JavaScript Function constructor, which compiles the source and throws a SyntaxError if the grammar is broken — but never executes it. That distinction is important: validation tells you the code parses, not that it behaves correctly. A missing bracket or stray comma is caught; a logic bug, an undefined variable used at runtime, or a typo in a method name is not. The exact error message from the engine (for example, "Unexpected token") is shown so you can jump to the problem.
When to use minify vs beautify
- Beautify when you have received cramped or generated code — an API response, a one-line config, a copied snippet — and need to actually read and edit it.
- Minify for a quick size win on small, standalone scripts or JSON payloads, or just to see how compact a blob can get. The character and line counters above the panes let you compare before-and-after sizes at a glance.
Common mistakes and limits to know
- This is not a production bundler. The JS minifier uses regular expressions, so it can mangle edge cases like a URL containing
//inside a template literal or a regex literal that looks like a comment. For shipping code, use a real tool such as Terser or esbuild; use this for quick, readable results. - JSON beautify reorders nothing but reformats everything. Trailing commas, comments, and single quotes are illegal in JSON and will push your input into the JS path — if you expected strict JSON output, enable JSON mode so a parse failure is reported instead of silently falling back.
- Validation is syntax-only. "Valid JavaScript" means it compiles, not that it runs without errors.
- Indent choice is cosmetic. Two spaces, four spaces, or a tab change readability and file size slightly but never the meaning of the code.
Is your code private?
Yes. Every operation — parsing, formatting, minifying, and validating — runs entirely in your browser using built-in JavaScript APIs. Nothing you paste is uploaded, logged, or sent to a server. You can disconnect from the network and the tool still works, which is the simplest proof that your code never leaves your machine.
Perguntas frequentes
Formate, valide e minifique JSON — com localização precisa de erros de sintaxe.
Format, validate, and explore JSON with syntax highlighting, JSONPath browser, tree collapse, and schema inference.
Formate JSON com destaque de sintaxe ou remova espaços em branco para minificar — com validação em tempo real e estatísticas de tamanho.
Embeleze e formate consultas SQL bagunçadas com indentação adequada e capitalização de palavras-chave — instantaneamente.
Minifique HTML, CSS e JavaScript para reduzir o tamanho do arquivo — funciona inteiramente no seu navegador.