JavaScript Formatter

One input per line. Output is numbered to match the input order.
Pinned tools are listed in your favourites on the home page.Copies a link to this tool that carries your current input, so it opens ready to run.Gives you an iframe snippet for putting this tool on your own site.
Note: For full JS/TS formatting, use Prettier in your editor.
Ctrl+Enter Run  · Ctrl+Shift+C Copy  · Esc Clear

Understand JavaScript Formatter

This tool tidies JavaScript or TypeScript text — line endings, trailing whitespace, and runs of blank lines — and pretty-prints the input as JSON when it detects JSON.

How it works

If the text starts with { or [ it is tried as JSON first and, when it parses, printed with two-space indentation. Otherwise the cleanup is purely textual: CRLF and CR line endings become LF, trailing whitespace is trimmed from every line, and three or more consecutive blank lines collapse to two. Nothing is parsed as code, so nothing your code means can be changed — and equally, indentation that is already wrong stays wrong.

When to use it

  • Normalizing line endings in a file that has been through both Windows and macOS editors.
  • Pretty-printing a JSON blob you found pasted inside a JavaScript file.
  • Tidying a snippet before pasting it into an issue or a code review comment.
  • Cleaning up generated output littered with stray blank lines and trailing spaces.

Watch out for

  • It does not re-indent. Minified JavaScript arrives on one line and leaves on one line — expanding it requires a parser that rebuilds the code from a syntax tree, which this is not.
  • Anything beginning with { or [ is tried as JSON, so a snippet that also happens to be a valid JSON object comes back reprinted as JSON rather than left as code.
  • Quote style, semicolons, spacing inside expressions, and line width are untouched, so this will not make a file match a Prettier config.

Not the right tool for: Formatting code you are about to commit. Prettier or your editor's formatter parse the code and produce a result that is stable across a whole team; use this for a quick tidy of text you are pasting somewhere.

Frequently Asked Questions

Why is this more basic than Prettier?

Full JS/TS AST parsing requires a 3–5 MB library. This tool handles quick cleanup — normalizing line endings, fixing indentation, collapsing extra blank lines, and detecting embedded JSON — without the overhead. For editor-integrated formatting, use the Prettier VS Code extension.

Can this format minified JavaScript?

Partially — it handles the most common pattern of minified JSON-like objects embedded in JS. Fully minified JS (all on one line, no spaces) requires a proper AST deparser which this tool does not include.

Does it handle ES modules and TypeScript?

The formatter is text-based (not AST-based), so it handles any valid JavaScript syntax including import/export, async/await, generics, and type annotations without understanding them. It won't incorrectly remove TypeScript-specific syntax.

How to Use JavaScript Formatter

  1. Paste or type your input in the input area above.
  2. The tool processes your input automatically or click Run.
  3. Copy or download the result using the action buttons.
  4. Use Ctrl+Enter to run quickly from the keyboard.