Code Formatter

Code Formatter

JSON formatter and validator, plus HTML, CSS, JavaScript and SQL formatting
PricefreeLocal processingOfflineAuto language detection

A code formatter for JSON, HTML, CSS, JavaScript and SQL

This page is a JSON formatter first, and a code formatter for four more languages: HTML/XML, CSS, JavaScript/TypeScript and SQL. Paste code, press Format, and it is re-indented in place — no upload, no sign-up, no installation.

The language is detected from the code itself and can be overridden in the Language list. An unquoted object such as {name: 1} is JavaScript, while {"name": 1} is JSON; that ambiguity is exactly why the manual choice is there.

Only whitespace is changed: line breaks and indentation are inserted, trailing spaces removed and a few separators tidied. Statements, quotes, letter case and token order stay as you wrote them, so the formatted code does exactly the same thing as the original.

Supported languages at a glance
LanguageWhat the formatter doesGood to know
JSONValidates the document, then pretty-prints it with 2 spaces, 4 spaces or tabs — the JSON formatter and validator in one stepSyntax errors report the line and column; a trailing comma, a comment or a single-quoted string is an error in JSON
HTML / XMLOne tag per line, nested tags indented; text and inline tags stay on the same lineThe contents of script, style, pre and textarea are left exactly as written
CSSOne declaration per line, nested blocks indented, one space after a declaration colonNo colon or comma spacing inside url(...) or inside media-query parentheses
JavaScript / TypeScriptOne statement per line, braces indented, a space before an opening braceWhitespace only — tokens are never rewritten, so unusual syntax stays valid
SQLEach clause (SELECT / FROM / WHERE / JOIN …) on its own line, AND / OR indentedKeywords keep the letter case you typed

JSON formatter: validate, beautify and pretty-print JSON

JSON is the most-used format on this page. Paste a JSON document and the tool parses it, validates it and prints it back with consistent indentation — 2 spaces, 4 spaces or tabs. Objects and arrays keep their order, and every string and number is reproduced exactly as it was parsed.

Because the document is parsed before it is printed, broken JSON is never silently reflowed. The JSON validator reports the line and column of the first syntax error — a missing comma, a trailing comma, a comment or a single-quoted string — and shows no output, so you can fix the file instead of guessing.

It is handy for reading a minified API response, checking a config file before committing it, or turning a one-line JSON blob into something reviewable in a pull request.

{
  "name": "nofun",
  "tags": [
    "json",
    "formatter"
  ],
  "nested": {
    "ok": true
  }
}

HTML and XML formatter

Markup is reformatted one tag per line, with nested tags indented a level deeper. Text and inline elements such as <b>, <a> or <span> stay on the same line as the surrounding words, so a paragraph keeps its original spacing when it is rendered again.

Nothing inside script, style, pre or textarea is touched — those blocks are copied through character for character, because their whitespace is part of the content.

CSS formatter

CSS is split into one declaration per line, nested blocks are indented, and a single space is added after a declaration colon. Selectors, at-rules such as @media and the conditions inside them are kept exactly as written.

Colons and commas inside url(...) and inside media-query parentheses are never touched, so a background URL or a min-width condition cannot be broken by formatting.

JavaScript and TypeScript formatter

JavaScript and TypeScript are re-indented statement by statement, with braces on their own lines and a space before an opening brace. Object members go one per line, while a for-loop header stays on one line.

The formatter only touches whitespace: it never deletes an existing line break, never changes quotes or letter case and never reorders tokens. That keeps automatic semicolon insertion and unusual syntax valid — the code behaves exactly as before.

SQL formatter

SQL is laid out clause by clause: SELECT, FROM, WHERE, GROUP BY, ORDER BY, JOIN and LIMIT each start a new line, and ON, AND and OR are indented one level. Subqueries in parentheses are indented as their own block.

Keyword letter case is left as you typed it, so a mixed-case query stays mixed-case — the formatter only decides where the line breaks go.

Frequently asked questions

Is this a JSON formatter?

Yes. The JSON formatter parses the document, validates it and pretty-prints it with 2-space, 4-space or tab indentation. If the JSON is invalid you get the line and column of the first error instead of a half-formatted result.

How do I format JSON with this tool?

Paste the JSON, leave Language on Auto-detect (or pick JSON), choose 2 spaces, 4 spaces or Tab, then press Format. The formatted JSON appears in the output box with a Copy button.

Does it validate JSON as well as format it?

Yes — validation happens first. A trailing comma, a comment, a single-quoted string or a missing bracket is reported with its line and column, and no output is produced.

Can it minify JSON?

No. This page is a JSON formatter and validator, not a minifier: it only adds line breaks and indentation. Use your editor or a dedicated minifier when you need to compress JSON.

Can it format HTML, CSS, JavaScript and SQL too?

Yes. The same page formats HTML/XML, CSS, JavaScript/TypeScript and SQL. The language is detected automatically and can be chosen from the Language list; each language has its own section above describing exactly what is changed.

What does this tool do?

It re-indents code: it inserts line breaks after statements and braces, indents nested blocks, and cleans up stray whitespace. Paste the code, press Format, and copy the result. The language is detected automatically and can be chosen manually.

How is the language detected?

By shape, not by file name. Input starting with { or [ that parses as JSON is JSON; input starting with a tag such as <div> or containing a closing tag is HTML/XML; input starting with SELECT, INSERT, UPDATE and similar keywords is SQL; input with CSS rules (a selector followed by "property: value;") is CSS; anything with functions, variables, arrows or braces is JavaScript. If the guess is wrong, pick the language from the list.

Can I choose the language myself?

Yes. Set Language to Auto-detect to let the tool decide, or pick JSON, HTML/XML, CSS, JavaScript/TypeScript or SQL explicitly. The manual choice wins over detection.

Does formatting change what my code does?

No. The formatter only adds line breaks and indentation, removes trailing spaces and tidies a few separators (such as the space after a colon). It never deletes an existing line break, never changes quotes or letter case, and never reorders tokens, so the code behaves the same way after formatting.

Why does it not rewrite my code the way Prettier does?

Because this is a browser-only tool with no build step or third-party formatter inside. It deliberately sticks to whitespace so that unusual or half-finished code still comes out as valid code rather than a broken rewrite. If you want opinionated rewriting — wrapping long lines, normalising quotes — use your editor's formatter.

Is my code uploaded anywhere?

No. Formatting happens entirely in your browser and works offline; nothing you paste leaves your device.

Which languages are not supported?

YAML, Markdown, Python, Java, C# and other languages have no formatter here yet. Choosing the closest supported language is not a substitute: it will not produce sensible output, so leave those for your editor.