Skip to main content
The JavaScript beautifier reformats and re-indents JavaScript source code. It can also unpack scripts packed by Dean Edwards’ popular packer and partly deobfuscate scripts processed by javascript-obfuscator.

Supported syntax

The beautifier handles modern JavaScript including:
  • ES6+ features: const, let, arrow functions, destructuring, spread/rest operators
  • Async/await and generator functions
  • Template literals and tagged templates
  • JSX-like syntax
  • Dynamic import() expressions
  • Optional chaining (?.) and nullish coalescing (??)

Before and after

The beautifier takes minified or poorly formatted code and produces readable output.
var x={a:1,b:2};function greet(name){if(name){return 'Hello, '+name+'!';}else{return 'Hello!';}}const arr=[1,2,3].map(n=>n*2);async function fetchData(url){const res=await fetch(url);return res.json();}

Key options

brace_style

Controls where opening and closing braces are placed. Accepts a comma-separated value: a style name, optionally combined with preserve-inline.
ValueDescription
collapseOpening brace on same line as statement (default)
expandOpening brace on its own line
end-expandClosing brace on its own line only
noneDo not adjust brace position
You can append ,preserve-inline to any value to keep single-line blocks on one line.
if (condition) {
    doSomething();
} else {
    doOther();
}

operator_position

When a line break occurs around a binary operator, this option controls which side of the break the operator appears on.
ValueDescription
before-newlineOperator stays at the end of the previous line (default)
after-newlineOperator moves to the start of the next line
preserve-newlineOperator position is not changed
var result = value1 +
    value2 +
    value3;

space_in_paren and space_in_empty_paren

space_in_paren adds padding spaces inside parentheses. space_in_empty_paren adds a single space inside empty parentheses.
// space_in_paren: false (default)
foo(a, b);
bar();

// space_in_paren: true
foo( a, b );
bar();

// space_in_paren: true, space_in_empty_paren: true
foo( a, b );
bar( );

jslint_happy

Enables stricter JSLint-compatible formatting. When true, it automatically sets space_after_anon_function to true, adding a space before anonymous function parentheses.
// jslint_happy: false (default)
var fn = function() {};
setTimeout(function() {
    doWork();
}, 100);

// jslint_happy: true
var fn = function () {};
setTimeout(function () {
    doWork();
}, 100);

keep_array_indentation

When true, preserves the indentation of array elements as written in the source. When false (default), the beautifier re-indents array contents.
// keep_array_indentation: false (default)
var matrix = [
    [1, 0, 0],
    [0, 1, 0],
    [0, 0, 1]
];

// keep_array_indentation: true
// original unusual indentation is preserved
var matrix = [[1, 0, 0],
               [0, 1, 0],
               [0, 0, 1]];

comma_first

When true, places commas at the beginning of each new line rather than at the end of the previous line.
// comma_first: false (default)
var obj = {
    a: 1,
    b: 2,
    c: 3
};

// comma_first: true
var obj = {
    a: 1
  , b: 2
  , c: 3
};

wrap_line_length

Sets a soft maximum line length. Lines that exceed this character count will be wrapped at the next opportunity. Set to 0 (default) to disable wrapping.
// wrap_line_length: 0 (default, no wrapping)
const result = someFunction(argumentOne, argumentTwo, argumentThree, argumentFour);

// wrap_line_length: 60
const result = someFunction(argumentOne, argumentTwo,
    argumentThree, argumentFour);

JSON beautification

You can use the JavaScript beautifier to format JSON. Pass a JSON string to js_beautify and it produces indented output.
const options = { indent_size: 2, space_in_empty_paren: true };

const dataObj = { completed: false, id: 1, title: "delectus aut autem", userId: 1 };
const dataJson = JSON.stringify(dataObj);

js_beautify(dataJson, options);

/*
{
  "completed": false,
  "id": 1,
  "title": "delectus aut autem",
  "userId": 1,
}
*/
For strict JSON output without trailing commas, use JSON.parse followed by JSON.stringify with a space argument instead. The JS beautifier is more permissive and useful when the input may not be 100% valid JSON.

All JS-specific options at a glance

Default: "collapse"
Values: collapse, expand, end-expand, none, optionally append ,preserve-inline
Controls placement of opening and closing braces.
Default: "before-newline"
Values: before-newline, after-newline, preserve-newline
Where to place binary operators when a line break is inserted around them.
Default: falseAdd padding spaces inside parentheses: f( a, b ).
Default: falseAdd a single space inside empty parentheses: f( ).
Default: falseEnable JSLint-stricter mode. Forces space_after_anon_function to true.
Default: falseAdd a space before anonymous function parentheses: function ().
Default: falseAdd a space before named function parentheses: function example ().
Default: falsePreserve the original indentation of array elements.
Default: falsePlace commas at the beginning of new lines instead of the end.
Default: 0 (disabled)Wrap lines that exceed N characters. 0 disables wrapping.
Default: falseBreak chained method calls across subsequent lines.
Default: falseDo not indent chained method calls.
Default: falseDecode printable characters encoded in xNN notation inside strings.
Default: falsePass E4X XML literals through untouched.