Skip to main content

JSON formatter

Paste a JSON document, reindent it for easier review, minify it when needed, and quickly detect syntax errors before reuse.

  • Clipboard
  • Export
Automate

Embed this widget

Customize the result, check the live preview, then copy the code.

Preview

Embed code type

Code to copy

Responsive and automatically resized by Bethemesh.

Indentation

Was this tool useful?

How does this tool work?

Compact JSON can be valid yet difficult to inspect. This formatter lays out a document using two spaces, four spaces or tabs; minification removes unnecessary whitespace outside strings. It checks syntax before producing output, so you can inspect an API response, prepare configuration or shorten a test fixture while retaining the written values. Objects and arrays are supported alongside standalone JSON values: a quoted string, number, true or null can also form a valid document.

The first step checks JSON grammar. Comments, trailing commas, unquoted keys and single-quoted strings are rejected. JavaScript and JSON5 snippets therefore need an explicit conversion first; the formatter does not guess how to repair ambiguous input.

After validation, the engine scans the original tokens. It retains names, member order, escaped strings and numeric spellings while adjusting whitespace between tokens. Output is not rebuilt from JavaScript numbers: 9007199254740993, 1e400 and -0 retain their original spelling. Duplicate properties are also retained, although they make exchanges less interoperable.

This checks syntax rather than your data contract. A well-formed object can still lack a required identifier or contain an incorrect unit. Use JSON Schema validation for supported type, range and required-field constraints. Use JSON Compare when object member order should not affect a comparison.

How to use this tool

  1. Paste or import the full document

    Supply JSON without Markdown fences or log prefixes. If parsing fails, check quotes, separators and matching array or object delimiters.

  2. Choose the layout

    Select two spaces, four spaces or tabs and format. Use minification to remove indentation; whitespace inside string values remains unchanged.

  3. Check and export

    Review relevant sections before copying or downloading the JSON result. Editing the source or indentation hides the previous result until you run it again.

Use cases

Inspect a nested API response

Expose the object and array structure to find a particular property. Spaces inside strings and escaped line breaks remain part of the values.

Review configuration before committing

Choose indentation that matches your repository, then inspect the changes. Formatting does not sort keys or remove duplicate members.

Prepare a compact fixture

Remove layout whitespace for a test or documentation example. This reduces the text size; it does not replace HTTP compression or reduce the amount of underlying data.

Examples

Minify without rounding numbers

The large integer, exponent, negative zero, repeated key and escaped quote survive unchanged. Only whitespace outside tokens is removed.

Input

{ "z":9007199254740993,"z":1e400,"a":-0,"s":"a \" b" }

Result

{"z":9007199254740993,"z":1e400,"a":-0,"s":"a \" b"}

Indent empty containers

With two spaces, each member starts on a separate line. Empty objects and arrays stay compact without extra blank lines inside them.

Input

{"empty":[],"object":{}}

Result

{
  "empty": [],
  "object": {}
}

Tips and best practices

  • Send identifiers as strings when they exceed the precision supported by your application, even though this formatter retains their exact written digits.
  • A duplicate property is not an array: some consumers retain only the last member with a given name.
  • Tab width depends on the editor. Choose spaces when the same visual alignment must be reproducible across different applications.
  • Processing stays in your browser rather than a formatting service. Still remove secrets before pasting an example into a public issue.

Sources and references

Frequently asked questions

Will formatting round large JSON numbers?

No. Output copies numeric tokens from the source rather than serializing parsed JavaScript numbers. A downstream application reading that JSON may still impose its own precision limits.

Why does a trailing comma or comment cause an error?

Those extensions are not JSON syntax. Remove them deliberately; the formatter does not silently discard them and risk changing the intended meaning.

Does valid output guarantee that my API will accept it?

No. Success confirms JSON grammar, not server rules. A schema can check supported additional constraints, while authorization and business rules need testing in your application.

Can I sort keys or compare two documents here?

The formatter keeps member order. JSON Compare checks two structures using its own comparison rules; that is a different task from preserving and laying out source tokens.

Related tools

Tools similar or complementary to this one.

Similar tools

Validate a JSON document against a schema and locate every error precisely.

DevelopmentFeaturedUse this tool

Compare two JSON documents and highlight structural differences.

DevelopmentUse this tool