Skip to content
SmaftyToolsSmaftyTools

JSON Formatter

Format, validate and beautify JSON online. Free JSON formatter with indentation options and key sorting — runs entirely in your browser.

About JSON Formatter

The JSON Formatter is a free online json formatter and json beautifier that turns raw or minified JSON into clean, properly indented output in seconds. It's built for the moments every developer hits constantly: pasting a squashed API response into a readable shape, reviewing a teammate's config file, or checking that a payload you're about to send actually parses. Front-end and back-end engineers, QA testers poking at API responses, and anyone maintaining JSON-based config files (package.json, tsconfig.json, OpenAPI specs) will find themselves reaching for it daily.

Beyond pretty-printing, the tool doubles as a strict json validator: invalid JSON — a missing comma, an unquoted key, a trailing bracket, a stray comment (JSON doesn't allow them) — is caught instantly, with an error message that names the problem instead of leaving you to scan character by character. Large, deeply nested payloads become much easier to scan once keys are sorted alphabetically, which is especially useful when diffing two versions of the same object or hunting for a specific field in a response with hundreds of keys. When you're done reviewing, the same tool can minify the JSON back down, stripping whitespace before it ships to production or gets embedded in a script tag.

Under the hood the formatter uses the browser's native JSON parser, so the validation you see here is exactly what JSON.parse would do in your own code — no approximated or lenient third-party parser papering over real errors. Formatting, minifying and key-sorting all happen instantly as you type or paste, with no network request and no size limit beyond what your browser's memory can hold, which makes it comfortable to use even on multi-megabyte API dumps.

Because everything runs client-side in JavaScript, sensitive payloads — auth tokens, customer records, internal API responses — never leave your device, which makes this a safe way to format json online even for data you wouldn't want to paste into a random third-party service.

Is it safe to use an online JSON formatter?

With this JSON Formatter, yes: every step runs in your browser with JavaScript. The page reads the text you paste, formats or validates it locally, and writes the result back to the page. There is no upload step and no server API, so auth tokens, customer records and internal API responses are not sent anywhere by the formatter. To verify that yourself: open DevTools with F12, switch to the Network tab, clear the list, then paste and format a test payload. Watch for any new request carrying your data; formatting this page sends none. One caveat applies to any online tool: a browser extension with permission to read page content could still observe what you paste. Use a clean profile or disable unknown extensions for sensitive data. The formatter's own code is client-side, but installed extensions are outside its control.

Fix common JSON parse errors

Most parse errors come from JavaScript habits that JSON does not allow. JSON.parse is strict: it accepts double-quoted strings and keys, commas between items, and no comments or trailing commas. The table below pairs each common mistake with the corrected form.

If the syntax is valid but the shape is wrong, check it against a schema with the JSON Schema Validator. For tabular payloads, JSON to CSV turns an array of objects into spreadsheet rows, and CSV to JSON rebuilds JSON from a spreadsheet export.

ErrorExampleFix
Trailing comma{"a": 1, "b": 2,}Remove the comma after the last value: {"a": 1, "b": 2}
Single quotes{'name': 'Ada'}Use double quotes for keys and strings: {"name": "Ada"}
Unquoted key{name: "Ada"}Wrap every key in double quotes: {"name": "Ada"}
Comments{"debug": true // note}Remove // and /* */ comments; JSON has no comment syntax.

2 spaces vs 4 spaces

JSON ignores whitespace between tokens, so indentation width never changes the data. Two spaces and four spaces are both valid; the choice is about readability and consistency, not correctness.

Use 2 spaces as the default for JavaScript and TypeScript projects, package.json, and deeply nested API responses. Narrow indentation keeps levels visible without pushing lines off-screen and fits the common style in the JavaScript ecosystem. Use 4 spaces when your repository, editor configuration, or team style guide already standardizes on 4. If a project has no convention, pick 2 and record it in .editorconfig so every editor agrees. If the same settings live in YAML, the YAML Formatter applies the same indentation discipline.

Format JSON in VS Code

VS Code ships with a built-in JSON formatter, so no extension is required for a file with valid JSON. If the file contains comments or trailing commas, strict JSON mode reports them as errors before formatting. For Base64-encoded values inside a JSON file, decode them with Base64 before formatting the enclosing object. The VS Code JSON documentation lists the built-in formatter and its settings.

  1. Open the .json file in VS Code.
  2. Press Shift+Alt+F on Windows or Linux, or Shift+Option+F on macOS. Alternatively, open the Command Palette (Ctrl+Shift+P, or Cmd+Shift+P on macOS) and run Format Document.
  3. If VS Code prompts for a formatter, choose the built-in JSON Language Features or your project's configured formatter.
  4. Save the file. To format on every save, enable Format On Save in Settings.

How to Use the JSON Formatter

  1. Paste or type your JSON into the input pane.
  2. Choose an indentation level (2 spaces, 4 spaces or tabs) and toggle key sorting if needed.
  3. The formatted result appears instantly in the output pane — fix any validation errors shown inline.
  4. Click Copy to grab the formatted JSON, or minify it for production use.

Features

  • Instant formatting and validation as you type
  • Configurable indentation and alphabetical key sorting
  • Minify mode to compress JSON for production
  • Clear, inline error messages for invalid JSON

Examples

Formatting a minified API response

Input

{"user":{"id":42,"name":"Ada Lovelace","active":true},"roles":["admin","editor"]}

Output

{
  "user": {
    "id": 42,
    "name": "Ada Lovelace",
    "active": true
  },
  "roles": [
    "admin",
    "editor"
  ]
}

Catching an invalid trailing comma

Input

{
  "a": 1,
  "b": 2,
}

Output

Error: Unexpected token '}' — a trailing comma is not valid JSON. Remove the comma after "b": 2.

Minifying before shipping to production

Input

{
  "env": "production",
  "debug": false
}

Output

{"env":"production","debug":false}

Frequently Asked Questions

What is a JSON formatter?

A JSON formatter takes raw or minified JSON text and pretty-prints it with consistent indentation and line breaks, making the structure easy to read. It also validates the syntax and reports errors.

Can it handle large JSON files?

Yes. Because processing happens locally in your browser, the formatter handles large payloads quickly — there is no upload step or server round-trip.

Is this a JSON validator too?

Yes — before formatting anything, the tool parses your JSON with the browser's native parser, so any syntax error is caught and reported immediately. If it formats successfully, the JSON is guaranteed valid.

Does the JSON Formatter upload my data?

No. Formatting, validation and minifying run in your browser with JavaScript. The tool does not send your JSON to a server for processing and does not store it; reloading the page clears the input. You can confirm this in DevTools: the Network tab shows no request containing your payload when you format. A browser extension that can read page content is outside the tool's control.

How do I fix a JSON parse error?

Read the parser's position and character, then check the four usual suspects: a trailing comma before } or ], single quotes instead of double quotes, an unquoted key, or a // or /* */ comment. JSON only allows double-quoted strings and keys, commas between items, and no comments. Paste the fixed text back into the formatter; it formats only when JSON.parse accepts the whole document.

Should I format JSON with 2 spaces or 4 spaces?

Either is valid, because JSON ignores whitespace between tokens. Use 2 spaces as a practical default for JavaScript and TypeScript projects and for deeply nested payloads; use 4 spaces if your repository or team already standardizes on it. What matters is consistency within a file and across the project, not the exact width.

Sources