JSON and code formatter

Tidy, check, or minify JSON, HTML, CSS, JavaScript, XML, and SQL. No record of your code is kept.

What to do

Paste it here. It's formatted as soon as you paste.

Paste your JSON

The tidy version appears here, ready to copy.

Formatted JSON

Tell us what happened and what you expected. Please leave out personal information and private tool inputs.

These details describe your setup. They don’t include your name, email, or anything entered into the tool.

See the details included

Voting-limit status from this browser is included. Reports are stored by Netlify so I can investigate.

What you get

Paste JSON from an API response, a log, or a config file, and it comes back indented and easy to read. This one-liner:

{"user":{"id":42,"name":"Sam","tags":["admin","beta"]},"active":true}

becomes:

{
  "user": {
    "id": 42,
    "name": "Sam",
    "tags": [
      "admin",
      "beta"
    ]
  },
  "active": true
}

Switch to Minify to get the one-liner back. The result shows the line count and the size before and after. For other code, pick the language from the menu: the same box formats HTML, CSS, JavaScript, XML, and SQL.

When the JSON is broken

The checker reads JSON the strict way the standard describes and stops at the first problem. It shows the line and column, the line itself with a marker under the spot, and what’s wrong in words, not codes:

Mistake Example Fix
Missing comma "a": 1 "b": 2 Add a comma between items
Comma after the last item [1, 2, ] Remove the last comma
Single quotes {'name': 'Sam'} Use double quotes
Key without quotes {name: "Sam"} Put the key in double quotes
Python or JavaScript words True, None, undefined Use true, false, or null
A comment // note Remove it; JSON has no comments

It also warns when the same key appears twice in one object. That’s allowed, but most programs keep only the last value, so it’s usually a mistake.

Other languages

HTML formatter

Each element goes on its own line, indented by depth, and CSS and JavaScript inside <style> and <script> are formatted too. Line breaks are only added where browsers ignore them, so inline tags like <b> and <a> stay with their words and the page looks the same. Minify removes comments and extra spaces but keeps <pre> and <textarea> text exactly.

CSS formatter

One property per line, a space after each colon, and media queries and nested rules indented by level. Minify removes comments and spaces and shortens what it safely can, like #ffffff to #fff. A missing } is reported with the line where the block opened.

JavaScript formatter

Unminifies scripts into readable code with consistent spacing, quotes, and semicolons. Modern syntax and JSX work; TypeScript type annotations don’t yet. Minify also shortens local variable names, so test minified code before you ship it.

XML formatter

Pretty prints XML, SVG, RSS, and sitemaps, and checks that every tag is closed in the right order. Errors name the tag, like “Expected </b> but found </a>”. It checks that XML is well formed, not that it matches a schema.

SQL formatter

Turns a one-line query into clauses on their own lines with keywords in capitals, and indents subqueries inside their brackets. Choose your SQL type (Standard, MySQL, PostgreSQL, SQL Server, or SQLite) so its keywords and quotes are read correctly. Text in quotes is never changed.

How it works

  • JSON is read character by character against the JSON standard (RFC 8259), with my own checker, so numbers and text are copied exactly as written.
  • HTML, CSS, JavaScript, and XML are formatted with Prettier, the open-source formatter many code editors use. SQL uses the open-source sql-formatter library.
  • Minifying uses csso for CSS and terser for JavaScript; HTML, XML, and SQL use my own careful minifiers that never touch quoted values or text inside tags.
  • Speed: each language’s formatter loads only the first time you use it, and big files are processed in the background so the page keeps working.

Limits

Only standard JSON is accepted: JSON5 and JSON with comments show an error at the first comment or unquoted key. Template code mixed into HTML, CSS, or SQL (PHP, Jinja, {{ }}) can confuse the formatter. Very large files, tens of megabytes, depend on your device’s memory.

FAQs

How do I know if my JSON is valid?

Paste it and press Format. If it's valid you get the tidy version. If not, you see the line and column of the first problem, what's wrong in plain words, and a button that selects that line in your text so you can fix it.

Why does my JSON say it's invalid when it works in JavaScript?

JSON is stricter than JavaScript. Keys and text need double quotes, there can't be a comma after the last item, and comments, undefined, NaN, and single quotes aren't allowed. The error message names which rule was broken.

Which languages can it format?

JSON, HTML, CSS, JavaScript (including JSX), XML (including SVG, RSS, and sitemaps), and SQL for MySQL, PostgreSQL, SQL Server, and SQLite. Pick the language from the menu above the box.

Does formatting change my code or data?

Formatting is intended to preserve meaning while changing layout and syntax style, such as JavaScript quotes and semicolons or SQL keyword capitalization. JSON numbers and text are kept exactly as written, including very long numbers. Review and test code before using it.

What's the difference between formatting and minifying?

Formatting adds readable spacing and indentation. Minifying removes unnecessary spacing and may remove comments or rewrite code to reduce its size. The output is intended to behave the same, but review and test it before replacing working code.

Should I indent with 2 spaces, 4 spaces, or tabs?

Any of them works. 2 spaces is the most common in web projects and keeps deep nesting readable. Use whatever the project you're pasting into already uses; the choice is remembered in this browser.

Is it safe to paste API keys or private data here?

The formatting runs in your browser. Your code isn't uploaded, stored, or added to the page address, and it's gone when you close the tab. Even so, treat secrets carefully anywhere you paste them.

Have an idea for a tool I should add? Send it in. I read every suggestion and choose which ones to build next.

For example: "Count the weekdays until a date, without holidays."

Please don't include your name, email, or anything personal. I don't need it. Voting-limit status from this browser is included.