Skip to main content

JSON Formatter & Validator

Format, minify, and recursively sort JSON while showing syntax-error line context and detailed object-structure statistics.

Indent
Waiting for input
0 B

Formatted Output

Formatted JSON appears here.

How to use the JSON Formatter

  1. 1

    Paste your JSON into the left text area, or click 'Sample' to insert an example.

  2. 2

    Select your preferred indentation style (2 spaces, 4 spaces, or tab) from the toolbar.

  3. 3

    The formatted JSON appears instantly in the right panel. Syntax errors are shown in red with full details.

  4. 4

    Click 'Copy' to copy the formatted output, or 'Minify' to produce compact JSON with whitespace removed.

Features

  • Estimated syntax-error line and column with two surrounding lines
  • Two-space, four-space, and tab indentation
  • Recursive key sorting at every object level
  • Object, array, key, value, depth, and minified-size statistics
  • Format, minify, copy, and JSON download actions

FAQ

Q. What syntax errors can it detect?

A. It parses JSON according to RFC 8259, detecting trailing commas, missing quotes, mismatched brackets and braces, invalid Unicode escapes, and all other standard JSON syntax errors.

Q. Does it support JSON5 or JSONC (JSON with comments)?

A. No. This tool validates against the JSON standard (RFC 8259). Comments (// or /* */) and trailing commas found in JSON5/JSONC will cause syntax errors.

Q. Can it handle large JSON files?

A. Yes. Everything runs in the browser. Files up to several MB work fine; very large files may increase browser memory usage.

Q. Can I validate JSON without formatting it?

A. Yes. Validation runs automatically as you type, and the status badge shows '✓ Valid JSON' or '✗ Error' instantly — no need to click Format. Live feedback is always active.

Technical Deep Dive: JSON Parsing, RFC 8259, and the Stringify Pipeline

Validation uses the standard JSON.parse() implementation. When a browser includes a character position in SyntaxError, the tool counts preceding line breaks to estimate a line and column and displays nearby source lines. Browser error formats differ, so only available location data is shown.

Formatting is handled by JSON.stringify(parsed, null, indent). The third argument — a space count (2 or 4) or a tab character '\t' — controls indentation depth. Each level of nesting increases the indentation by one unit, dramatically improving readability of deeply nested structures. Passing null as the replacer argument causes JSON.stringify to automatically omit properties with undefined, function, or Symbol values, which cannot be represented in standard JSON.

Minification — the inverse of formatting — is equivalent to JSON.stringify(parsed). It removes all optional whitespace, producing the most compact representation of the same data. This is valuable for reducing API response sizes, minimizing localStorage usage, and removing unnecessary bytes before network transmission.

RFC 8259 (the IETF standard) and ECMA-404 (the Ecma Language Specification) are the two canonical JSON specifications. Both explicitly prohibit trailing commas, comments, and serialization of NaN or Infinity values. These restrictions are precisely why JSON5 and JSONC were created as supersets, but this tool targets the interoperable RFC 8259 standard used by all HTTP APIs and language parsers.

Security & Privacy

JSON parsing and formatting run in the browser's JavaScript engine, and this feature does not make a request that uploads the input to the Site. Remove or revoke production API keys and tokens before pasting whenever possible.

JSON.parse() and JSON.stringify() process the text locally. Device-side risks such as shared computers, clipboard history, untrusted extensions, or malware remain outside the protection this tool can provide.

Data in the textarea is held only in React state (browser memory). Closing or refreshing the page clears it immediately. This service performs no server-side logging or analysis of any pasted JSON content.

Examples, Validation Cautions, and Common Mistakes

Examples

  • Format API responses to inspect nested objects and arrays.
  • Validate configuration files before saving or deploying them.
  • Beautify minified JSON for review, debugging, and team communication.

Cautions

  • Commented JSON and trailing commas are invalid in strict JSON.
  • Remove tokens and personal data before sharing JSON snippets.
  • Valid JSON syntax does not guarantee the required API fields or types are correct.

Common Mistakes

  • Pasting JSONC or JavaScript object literals and expecting strict JSON validation to pass.
  • Fixing syntax only while ignoring meaning, schema, or type mismatches.
  • Sharing production logs with access tokens still included.