JSON Formatter

Format messy JSON, validate syntax, and beautify output instantly—perfect for developers and APIs.

Loading tool…

By Muhammad Abdullah Rauf · Founder, EverydayTools.proUpdated 2026-05-17· Reviewed by EverydayTools Editorial Team

What is a JSON formatter?

A JSON formatter adds consistent indentation and line breaks to compact or unformatted JSON, making the data structure immediately readable without changing any values.

JSON (JavaScript Object Notation) is the universal data interchange format — used by virtually every REST API, configuration file, and database export. When JSON arrives minified (no whitespace) or inconsistently indented, nested structures become unreadable: {"user":{"id":42,"roles":["admin","editor"]}} is immediately clear once each level is indented.

A JSON formatter applies consistent indentation (2 or 4 spaces), adds line breaks after every key-value pair and array item, and validates syntax in the same pass. The data itself is unchanged — input and output represent identical structures. The companion operation, minification, reverses this by stripping all whitespace to reduce payload size for production API calls.

Quick answers

Concise answers for common searches — definitions, steps, and comparisons.

What are the valid data types in JSON?

JSON supports exactly six value types: string (double-quoted), number (integer or decimal, no quotes), boolean (true or false, lowercase), null, object ({key: value} pairs), and array ([value, value]). JSON does not support: undefined, functions, Symbol, NaN, Infinity, single-quoted strings, or comments. A key that maps to undefined is silently dropped by JSON.stringify() — use null instead.

What characters must be escaped inside a JSON string?

Inside a JSON string, these characters must be escaped with a backslash: " (double quote → \"), \ (backslash → \\), and control characters (newline → \n, tab → \t, carriage return → \r, form feed → \f, backspace → \b). Unicode escapes use \uXXXX notation. Unescaped control characters cause a SyntaxError.

How do I minify JSON to reduce an API payload size?

Minification removes all whitespace between tokens: JSON.stringify(JSON.parse(input)) returns compact JSON with no spaces or line breaks. A typical well-indented JSON object compresses 15–30% by minification. For a REST API that transfers hundreds of KB per request, minification reduces bandwidth and speeds parsing. The data is structurally identical — only whitespace is removed.

How to use JSON Formatter

  1. Paste your JSON

    Copy raw JSON from an API response, log output, or config file and paste it. The formatter accepts minified single-line JSON, partially indented JSON, and will flag broken JSON.

  2. Choose indentation

    Select 2 spaces (JavaScript/TypeScript convention) or 4 spaces (Python/Java convention). Both produce valid, equivalent JSON — choose based on your project's style guide.

  3. Review validation feedback

    If your JSON is invalid, the error message shows the exact line and column of the syntax problem. Fix errors before copying to avoid downstream parsing failures.

  4. Copy, download, or minify

    Click 'Copy' to grab formatted JSON, 'Download' to save as a .json file, or 'Minify' to compress the output back to a single line for production payloads.

Who uses JSON Formatter?

Common real-world scenarios where this tool saves time.

Debugging API responses

Paste raw minified API output to instantly see the nested structure and identify missing or unexpected fields. Works with any REST or GraphQL response body.

Validating config files before committing

Validate package.json, tsconfig.json, .eslintrc, manifest.json, or any JSON config before committing — catches trailing commas, missing brackets, and unquoted keys before CI fails.

Reviewing webhook payloads

Stripe, GitHub, and Shopify webhooks arrive as minified JSON. Format them to trace missed events, verify payload structure, and identify which fields triggered your handler logic.

Data migration and ETL prep

Normalize inconsistent JSON from external data sources before feeding into an ETL pipeline, database import, or transformation script — catches malformed records before they reach production.

Workflow guides

Step-by-step chains that connect related tools for common tasks.

API debugging: validate before you format

When a REST API response looks broken, confirm syntax before prettifying — formatting invalid JSON does not fix parse errors and can hide the failure point.

  1. Paste the raw response into JSON Validator to get the exact line and column of any syntax error.
  2. Once valid, prettify the payload here (or paste the corrected string from the validator).
  3. If the payload includes access_token or a JWT string, open JWT Decoder to inspect claims and exp (Unix timestamp).
  4. For created_at, updated_at, iat, or exp fields, convert Unix timestamps with Timestamp Converter — 10 digits = seconds since epoch (POSIX), 13 digits = milliseconds (JavaScript Date.now()).
  5. To pull IDs or timestamps from unstructured log lines before parsing JSON, test a pattern in Regex Tester , then paste captured values into the converter.

Config review before commit

  1. Validate package.json, tsconfig.json, or manifest files in JSON Validator first.
  2. Format the valid file here with 2-space indent to match Prettier and npm defaults.
  3. Compare two environment configs with JSON Diff when you need a field-level change list between staging and production.

JSON Formatter examples

Format a minified API response

Input

{"status":"ok","user":{"id":42,"email":"alice@example.com","roles":["admin","editor"]},"created_at":1746172800}

Output

{
  "status": "ok",
  "user": {
    "id": 42,
    "email": "alice@example.com",
    "roles": [
      "admin",
      "editor"
    ]
  },
  "created_at": 1746172800
}

The formatted output reveals the nesting depth — user is an object containing id, email, and a roles array. The raw minified version requires scanning for brackets to understand the same structure. Formatting is the first debugging step when an API returns unexpected data.

Catch a trailing comma syntax error

Input

{"name": "alice", "active": true, "score": 98,}

Output

SyntaxError: Unexpected token } — line 1, column 46

Trailing commas after the last property are valid JavaScript but invalid JSON. This is the most common cause of JSON.parse() failures when copy-pasting object literals from JS code into API request bodies or config files.

How JSON formatting works

The formatter passes input to the browser's native JSON.parse(), which throws a SyntaxError with the byte offset of the first invalid character. On success, JSON.stringify(parsed, null, indentSize) re-serializes the structure with configurable indentation. Minification calls JSON.stringify(parsed) with no indent argument. Both operations run entirely in the JavaScript main thread and are O(n) in input length.

Formula

Format: JSON.stringify(JSON.parse(input), null, indentSpaces)
Minify: JSON.stringify(JSON.parse(input))
Error: SyntaxError at byte N → converted to line:column

Limitations

  • Key ordering is not guaranteed by ECMA-404 — V8 preserves insertion order for string keys in practice but this is not spec-mandated
  • Integers larger than Number.MAX_SAFE_INTEGER (2^53 − 1 = 9,007,199,254,740,991) lose precision when parsed as JavaScript numbers
  • Comments and trailing commas are invalid JSON — use a JSONC-aware parser for tsconfig.json and VS Code settings files

Reference tables

JSON vs YAML vs XML: choosing a data interchange format

Each format has strengths suited to specific ecosystems. JSON is the default for APIs; YAML dominates in DevOps tooling; XML is mostly legacy.

FormatSyntax styleBest forNot ideal for
JSONBraces, brackets, double-quoted keysREST APIs, config files, JavaScript data exchangeHuman-edited files that benefit from comments
YAMLIndentation-based, minimal punctuationDevOps configs (Kubernetes, GitHub Actions, Ansible)Machine-to-machine exchange; whitespace bugs are common
XMLVerbose open/close tags with attributesEnterprise systems, SOAP APIs, SVG, XSLT pipelinesReadability, file size, simplicity
JSONCJSON + // and /* */ commentsVS Code settings.json, developer tool configsStandard JSON parsers; technically not valid JSON
JSON5Relaxed: unquoted keys, trailing commas, commentsHuman-maintained config filesStrict RFC 8259 compliance requirements

JSON is the default for programmatic data exchange. YAML is dominant in DevOps tooling. XML is mostly legacy except in enterprise and document-centric contexts.

When to use JSON Formatter vs related tools

Related toolUse this tool whenUse related tool when
JSON ValidatorYou want to format readable output and validate in one step, or need to minify the output.You only need a pass/fail validity check with the precise error location, without reformatting the output.
YAML FormatterYour data is in JSON format — API responses, config files, package.json.Your config is in YAML format — GitHub Actions, Kubernetes, Docker Compose, Ansible.
JSON Diff ViewerYou have one JSON payload to inspect, validate, and clean up.You have two JSON objects and need to identify exactly what changed between them.
JWT DecoderYou have a raw JSON API response to format and explore — including any string fields that happen to be tokens.You have identified a JWT token string inside the JSON payload (the value of an 'access_token', 'token', or 'authorization' field) and need to decode its header and claims.
Timestamp ConverterYou need to format the full JSON response and see which fields contain Unix timestamps.You have identified a numeric Unix timestamp field (created_at, updated_at, iat, exp) in the formatted JSON and want to convert it to a readable date.

Best practices

Always format API responses before debugging

Minified JSON forces you to count brackets to find nesting depth. Formatting takes one second and eliminates most of the cognitive overhead when a field is missing or the structure is deeper than expected.

Use 2-space indent for JavaScript and TypeScript projects

Prettier, ESLint, and npm defaults all use 2-space indent. Consistent indentation reduces diff noise in code reviews and aligns config files with the rest of the codebase.

Minify before embedding JSON in application bundles

A 100 KB config with 2-space indent is approximately 70 KB minified — a 30% reduction. Minified JSON parses marginally faster and reduces network transfer in API responses.

Validate every JSON config file before committing

Trailing commas, missing brackets, and JSONC comment syntax are the top causes of CI build failures in package.json, tsconfig.json, and manifest.json. A 3-second validation prevents a 3-minute CI queue wait.

Common mistakes to avoid

Single-quoted strings instead of double quotes

JSON requires double quotes for all keys and string values. {name: 'alice'} is valid JavaScript but invalid JSON. Use double quotes: {"name": "alice"}. The formatter shows the exact character position of the error.

Trailing comma after the last element

[1, 2, 3,] and {"a": 1,} are invalid JSON, though they are valid JavaScript. Remove the comma after the final item. This is the most common source of JSON.parse() errors when copying from JS files.

Including comments in .json files

JSON does not support // or /* */ comments. They work in JavaScript and TypeScript's tsconfig.json (which uses JSONC format), but not in files parsed by JSON.parse(). Move comments to external documentation or use a JSONC parser.

Using undefined instead of null for absent values

JSON.stringify() silently drops object properties set to undefined and converts undefined array items to null. The result looks like the property never existed. Use null for intentionally absent values: { "result": null }.

BOM character at the start of a .json file

Windows Notepad and some export tools prepend a UTF-8 BOM (\uFEFF) when saving. The character is invisible in most editors but causes JSON.parse() to throw 'Unexpected token' in Node.js and strict server parsers. Always save JSON files as UTF-8 without BOM.

Troubleshooting

JSON.parse() still fails in my code after the formatter says it's valid

Likely cause: BOM character (\uFEFF) at the start of the string — common in JSON files saved by Windows Notepad

Fix: Strip the BOM before parsing: input.replace(/^\uFEFF/, ''). The browser JavaScript engine accepts BOM-prefixed input silently; Node.js and strict server parsers do not.

Large integers change value after formatting

Likely cause: IEEE 754 double-precision cannot represent integers above 2^53 − 1 exactly. Snowflake IDs and database bigint values above 9,007,199,254,740,991 are silently rounded.

Fix: Store large IDs and 64-bit timestamps as strings in JSON: { "id": "9007199254740993" }. The Twitter and Discord APIs both use this pattern for their ID fields.

Formatted JSON is valid but the API rejects it with a 400 error

Likely cause: JSON body is double-encoded (a string containing JSON), Content-Type header is missing, or a BOM was introduced during copy-paste

Fix: Verify Content-Type: application/json is set. Confirm the raw body is the JSON string directly, not URL-encoded or wrapped in another layer of quotes.

Key order changed after formatting

Likely cause: V8 sorts integer-like string keys numerically before other string keys — a non-obvious engine behavior

Fix: JSON key order is not guaranteed by the ECMA-404 spec. If your API or snapshot test depends on key order, sort keys explicitly in the producing code rather than relying on JSON.stringify output order.

A property I expected is missing from the formatted output

Likely cause: undefined, functions, and Symbol values are silently stripped by JSON.stringify — they have no JSON representation

Fix: Replace undefined with null before serializing. JSON.stringify({ a: undefined }) returns {} — the key disappears entirely. Use null for intentionally absent values: { "a": null }.

Advertisement

Frequently Asked Questions

What JSON syntax errors does it detect?

Trailing commas after the last element, unmatched braces and brackets, single-quoted strings, unquoted keys, missing commas between items, invalid Unicode escape sequences (\uXXXX), and invalid number formats. Each error reports the exact line and column number.

What is the difference between JSON and JavaScript object syntax?

JavaScript objects allow unquoted keys ({name: 'alice'}), single-quoted strings, trailing commas, and comments. JSON requires double-quoted keys ({"name": "alice"}), no trailing commas, and no comments. All valid JSON is valid JavaScript, but not vice versa — this mismatch is the source of most copy-paste errors.

Can it handle large JSON files?

Yes. Processing runs locally so there is no upload size limit or server timeout. Most JSON under 10 MB formats instantly. Files above 50 MB may take a few seconds depending on your device.

What is the difference between formatting and minifying?

Formatting adds indentation and line breaks for human readability. Minifying removes all whitespace to reduce file size — typically 15–30% smaller — for production API payloads and bundle assets. This tool handles both: format for debugging, minify for deployment.

Is this JSON formatter free?

Yes — completely free, no signup required, no usage limits. It runs entirely in your browser.

Does the JSON formatter fix errors automatically?

No — the formatter reports the exact line and column of the first syntax error but does not auto-correct it. JSON has strict syntax rules and any 'fix' would require guessing your intent (for example, whether a missing comma or an extra bracket is the true problem). Use the error location to find and correct the issue, then paste again.

What is minified JSON and why would I use it?

Minified JSON has all whitespace (spaces, newlines, tabs) removed, producing a compact single-line string. It is functionally identical to formatted JSON but smaller — typically 15–30% fewer bytes. Use minified JSON in production API responses, HTTP request bodies, and application bundles to reduce payload size and speed up parsing.

What is the difference between JSON and JSONP?

JSON is a pure data format. JSONP (JSON with Padding) is a legacy browser workaround that wraps a JSON payload in a JavaScript function call — for example, callback({"key":"value"}) — to bypass the same-origin policy. JSONP is not valid JSON and cannot be parsed by JSON.parse(). Modern APIs use CORS instead; JSONP is rarely used in new development.

Does this formatter support JSON5 or JSONC?

No — the formatter uses the browser's native JSON.parse(), which implements strict RFC 8259 JSON only. JSON5 (unquoted keys, trailing commas, comments) and JSONC (JSON with comments, used in VS Code settings) are supersets of JSON. If you paste JSON5 or JSONC with comments or trailing commas, the formatter will report a syntax error. Remove non-standard syntax before formatting.

How large a JSON file can I format?

There is no server-side file size limit because everything runs in your browser. JSON under 10 MB formats instantly on most devices. Files between 10–50 MB may take a second or two. Files above 50 MB can slow down or temporarily freeze the tab on lower-powered devices. For very large JSON, consider streaming parsers or command-line tools like jq.

Can I format JSON that contains comments?

Not directly — standard JSON (RFC 8259) does not allow comments, so JSON.parse() will throw a SyntaxError. To format JSON with comments, first strip them manually or use a JSONC-aware tool. VS Code's settings.json and tsconfig.json use JSONC, which supports // comments but requires a JSONC parser rather than a standard JSON formatter.

Is this the same as using Prettier for JSON?

Functionally similar for basic formatting. Prettier applies its own opinionated style (always double quotes, specific bracket spacing) and can be configured per project. This formatter uses JSON.stringify() with configurable 2- or 4-space indent — equivalent to Prettier's JSON output for standard files. The main difference: this tool runs instantly in the browser with no install, while Prettier is a project dependency for editors and CI pipelines.

Privacy, accuracy, and trust

Privacy

All formatting, validation, and minification runs in your browser using the JavaScript engine. No data is ever sent to any server — safe for API keys, tokens, database credentials, and any sensitive payload.

Accuracy

Formatted output is semantically identical to input. The tool uses the same JSON.parse / JSON.stringify pipeline as Node.js and all major browsers. There is no custom parser or transformation.

Formatted output is for human readability only. Validate JSON before using in production systems.

Part of Developer Tools

More free tools for the same workflow.

Advertisement

Reviewed by EverydayTools Editorial Team on 2026-05-14.