Code Formatter & Beautifier

Format common code, data, markup, and document languages locally in your browser.

One formatter for the code you paste every day

Pick a language in Format as, paste the code and click Beautify. The suite re-indents the code consistently, puts one statement per line and cleans up trailing whitespace, all inside your browser. Nothing is uploaded, so it is safe for code from private repositories, logs and config files. Links can open a language directly with ?mode=, for example ?mode=python, ?mode=php or ?mode=lua.

What each mode does

LanguagesHow they are formatted
C, C++, C#, Java, JavaScript, TypeScript, PHP, Perl, GraphQLBrace-aware re-indenter: splits statements at ;, { and }, puts each brace on its own line and indents two spaces per level
PythonIndentation-aware: reads the existing block structure and rewrites it with four spaces per level, converts tabs, keeps bracket continuation lines and triple-quoted strings intact, so the program's meaning does not change
Lua, RubyKeyword-aware: counts block openers (function, if ... then, do, def, class) against end, ignoring words inside strings and comments
HTML, XML, SVG, XAMLOne tag per line, nested two spaces deep; self-closing tags and comments do not change the depth
JSONParsed and printed with two-space indentation; invalid JSON shows the parser error
YAMLParsed with js-yaml and dumped with two-space indentation; multi-document files are kept, and comments are dropped (you are warned)
SQLStarts a new line before each major clause (SELECT, FROM, WHERE, JOIN, ORDER BY...)
MarkdownNormalises ATX headings (##Title to ## Title), blank lines around headings and code fences, and aligns table columns; fenced code is never touched, and MDX import/export lines are kept as written
Plain textOptional cleanups: trim trailing spaces, collapse repeated spaces, limit blank lines and capitalise sentences

Examples

C, one line in, readable block out:

int main(){int x=1;if(x){printf("hi");}return 0;}
int main()
{
  int x=1;
  if(x)
  {
    printf("hi");
  }
  return 0;
}

Python with inconsistent indentation (two spaces, then six) comes back as standard four-space PEP 8 indentation:

def f(x):
    if x:
        return 1
    return 0

Lua written flush-left, function f(x) / if x then / return 1 / end / end, is indented by block, with each end lined up under the line that opened it.

Language guides: Ruby, Perl, XAML, Angular and Babel

These languages used to have their own small pages on NeatJSON. They now live here, and each link below opens the formatter with the right mode already selected.

Ruby formatter and beautifier

Choose Ruby to re-indent Ruby with two spaces per level. def, class, module, if, unless, case, begin and do blocks (and open brackets) start a new level, and end closes it. Trailing modifiers such as return if x.nil? and endless methods like def y = 1 do not open a block, so they never push the following lines too far right. Heredocs and =begin/=end comments are copied exactly as written.

class Greeter
  def hi(name)
    puts "Hi #{name}" unless name.nil?
  end
end

The output follows the common two-space Ruby style. Inside a project, RuboCop or the Ruby LSP formatter can enforce your team's full style guide.

Perl formatter and beautifier

Choose Perl to break Perl code at braces and semicolons and indent each block by two spaces. A one-liner such as sub double { return $_[0]*2; } becomes a three-line subroutine you can read and edit. Treat it as a quick readability pass for snippets from logs, forums or minified scripts; it is not a replacement for perltidy, which also handles line length, spacing around operators and many style options.

XAML beautifier

Choose XAML to indent WPF, UWP, WinUI and .NET MAUI markup. Every element goes on its own line and children are nested two spaces deeper, so a <Grid> holding a <StackPanel> and a <Button Content="OK"/> reads top to bottom. Attributes stay on the same line as their element, and self-closing tags and comments do not change the depth. For large XML files with validation, use the XML formatter.

Angular template formatter

Angular component templates are HTML with extra syntax, so choose HTML. Each tag goes on its own line and nested elements are indented by two spaces, while structural directives (*ngIf, *ngFor), bindings ([value], (click)) and interpolations ({{ user.name }}) are kept exactly as written. For example, <div *ngIf="user"><span>{{ user.name }}</span></div> becomes three readable lines. Component classes are TypeScript: format them with the TypeScript formatter.

Babel and modern JavaScript formatter

Code written for Babel is ordinary modern JavaScript, so choose JavaScript. The brace formatter splits statements at braces and semicolons and indents each block by two spaces, which turns minified or one-line ES2015+ snippets (arrow functions, classes, async/await) into readable code. It only changes whitespace: it does not transpile, so the output still needs Babel if you target older browsers. For React components, use the JSX formatter.

Dedicated formatter pages

These languages also have their own page with notes for that language: Python formatter, PHP formatter, C formatter, C++ formatter, TypeScript formatter, JSX formatter, GraphQL formatter, Lua beautifier, Markdown formatter, MDX formatter, SVG formatter, Avro formatter and text formatter.

When to use a dedicated tool instead

This suite is a re-indenter, not a full compiler-grade pretty-printer: it does not reflow long lines, add spaces around operators or rename anything, which also means it cannot break working code. For deeper formatting use the dedicated tools: the JSON formatter (validation, repair and tree view), XML formatter, SQL formatter (full keyword casing and dialects), CSS beautifier, JavaScript beautifier and HTML formatter. Local tools such as Prettier, Black, gofmt and clang-format are the right choice inside a project, because they apply your team's settings on every save.

FAQ

Is my code uploaded?

No. Every formatter runs as JavaScript in your browser. Only the YAML parser library is downloaded from a CDN the first time you format YAML.

Will formatting change how my Python runs?

No. The Python mode keeps the block structure it reads and only changes the width of the indentation, so the parsed program is the same. It never joins or splits statements.

Can I format SOAP, WSDL, XAML or SVG?

Yes. They are all XML, so choose XML, SVG or XAML. For large XML documents with validation, use the XML formatter.

Why are my braces on their own lines?

The brace formatter uses one consistent layout (Allman style) for every brace language so the output is predictable. If your project uses K&R style, run your own formatter after pasting.

Does it support JSX, Angular templates and Markdown with JSX (MDX)?

JSX and TypeScript go through the brace formatter (choose JavaScript or TypeScript), Angular templates through HTML, and MDX through Markdown, which keeps import and export lines as written.

How do I format Ruby or Perl code online?

Choose Ruby or Perl in Format as, paste the code and click Beautify. Ruby is indented two spaces per block, counting def, class, if and do against end; Perl is split at braces and semicolons and indented two spaces per block. Nothing is uploaded.

Can I format Angular templates or Babel code?

Yes. Angular templates are HTML, so choose HTML; directives, bindings and {{ }} interpolations are kept as written. Babel source is modern JavaScript, so choose JavaScript. The formatter only changes whitespace and never transpiles.