Developer

JSON Formatter & Validator Guide (2026): Pretty-Print, Validate, Minify, and Convert JSON

A JSON formatter takes minified or hard-to-read JSON and turns it into pretty-printed, indented, color-coded output you can actually read. A JSON validator tells you exactly where a syntax error is (line 12, column 4, "Unexpected token }"). A JSON minifier does the opposite — strips all whitespace to shrink files by 20-40% for production APIs. This guide shows you how all three work, the 6 most common JSON errors and how to fix each one, the difference between JSON and JSON5, the basics of JSON Schema for serious validation, and how to convert JSON to TypeScript interfaces in one click. Everything runs in your browser, no signup, no upload.

Quick Answer: What a JSON Formatter & Validator Does

JSON formatter, validator, and minifier — at a glance

3core actions
<1sto format 10KB
20-40%minify savings
6common errors
100%in-browser
$0no signup

Try our free JSON Editor — formats, validates, minifies, and converts to TypeScript in one click. Or the JSON to TypeScript Converter if you already have valid JSON and just want the interfaces.

Before/after: the same JSON, formatted vs minified

Minified (1 line, 73 bytes):

{"name":"Alex Chen","age":30,"email":"alex@example.com","active":true,"roles":["admin","user"],"address":{"city":"Toronto","country":"CA"}}

Pretty-printed (8 lines, 187 bytes, with 2-space indent):

{ "name": "Alex Chen", "age": 30, "email": "alex@example.com", "active": true, "roles": ["admin", "user"], "address": { "city": "Toronto", "country": "CA" } }

Both are valid JSON. The pretty-printed version is 156% larger (187 vs 73 bytes) but infinitely more readable. The minified version is what APIs send over the wire. A JSON formatter is the tool that converts between the two — and validates the input as it does so.

What Is JSON? (The 30-Second Spec)

JSON stands for JavaScript Object Notation. It's a text-based data format defined by RFC 8259 (the current IETF standard, published in 2017) that humans can read and machines can parse. Despite the "JavaScript" in the name, JSON is language-independent — every modern language has built-in support for it (Python json, Ruby JSON, Go encoding/json, Java Jackson, C# System.Text.Json, PHP json_encode).

The 6 data types JSON supports

  • string — text in double quotes: "hello", "Toronto"
  • number — integer or decimal, no quotes: 42, 3.14, -7
  • booleantrue or false (no quotes, no capitalisation)
  • nullnull (no quotes) representing the absence of a value
  • array — ordered list in square brackets: [1, 2, 3]
  • object — unordered key-value pairs in curly braces: {"key": "value"}

The 4 structural rules JSON enforces

  1. Objects and arrays nest freely — a value can be any of the 6 types, including another object or array.
  2. Keys must be double-quoted strings{"name": "Alex"} is valid; {name: "Alex"} and {'name': 'Alex'} are not.
  3. No trailing commas{"a": 1, "b": 2} is valid; {"a": 1, "b": 2,} is not (this trips up everyone coming from JavaScript objects or Python).
  4. No comments — JSON does not support // or /* */ comments. If you need comments, use JSON5 or JSONC.

These 4 rules account for 90% of the JSON errors developers hit. A JSON validator catches every one of them and tells you exactly which line and column broke.

The 6 Most Common JSON Errors (and How to Fix Each)

Every JSON error has the same shape: unexpected token at a specific line and column. A good validator tells you both. Here are the 6 errors you'll hit most often, with the exact fix for each:

Error 1: Trailing comma

{ "name": "Alex", "age": 30, <-- trailing comma (invalid) }

Fix: Remove the comma after the last item. JSON does not allow trailing commas in objects or arrays (even though JavaScript and Python do). Validator message: Unexpected token } at line 3 column 11.

Error 2: Single-quoted strings

{'name': 'Alex', 'age': 30}

Fix: Replace all single quotes with double quotes: {"name": "Alex", "age": 30}. JSON only accepts double-quoted strings. Validator message: Unexpected token ' at line 1 column 1.

Error 3: Unquoted object keys

{name: "Alex", age: 30}

Fix: Wrap all keys in double quotes: {"name": "Alex", "age": 30}. Validator message: Unexpected token n at line 1 column 2.

Error 4: Comments

{ // user data "name": "Alex" }

Fix: Delete the comment. JSON does not support // or /* */ comments. If you need comments, switch to JSON5 (Babel/ESLint/VS Code config format) or use a separate _comment field. Validator message: Unexpected token / at line 2 column 3.

Error 5: Mismatched brackets/braces

{ "items": [ {"id": 1}, {"id": 2} ] } <-- extra closing brace }

Fix: Count opening {/[ against closing }/] — they must match. Most editors highlight mismatched brackets in red. Validator message: Unexpected end of JSON input or Unexpected token } at line 6 column 3.

Error 6: Invalid number formats

{"price": $9.99, "qty": 1,000}

Fix: JSON numbers are bare digits with optional decimal, sign, or exponent. No currency symbols, no thousand separators, no leading zeros. The fix: {"price": 9.99, "qty": 1000}. Validator message: Unexpected token $ at line 1 column 11.

Pro tip: Use our free JSON Editor to paste your broken JSON, and the validator will highlight the exact character that's wrong. Most other online formatters just say "Parse error" without telling you where.

How to Format JSON (3 Steps)

Formatting JSON takes 3 steps and under 1 second. Here's the exact workflow:

  1. Paste your JSON into the input box. Minified, single-line JSON works fine — the formatter will re-indent it.
  2. Click Format (or press Ctrl+Enter / Cmd+Enter). The tool parses the JSON, validates it, and outputs pretty-printed output with consistent 2-space indentation and syntax highlighting.
  3. Copy the formatted output using the copy button or Ctrl+A / Ctrl+C. The output is now ready to read, share, commit to Git, or paste into documentation.

Formatting options most formatters offer

  • Indent size — 2 spaces (most common), 4 spaces, or tabs. 2 is the de facto standard in JavaScript/Node codebases.
  • Sort keys alphabetically — useful for diffing JSON in version control (sorted JSON produces smaller diffs when keys change).
  • Escape unicode — converts "café" to "caf\u00e9". Off by default; enable for legacy systems that don't handle UTF-8.
  • Quote style — always double quotes (JSON spec requirement; no other option is valid).
  • Trailing newline — adds a newline at the end of the output. POSIX-friendly, but most formatters leave this off.

Our free JSON Editor supports all of these as one-click toggles. Try the same input with 2-space and 4-space indent to see which your team prefers.

How to Minify JSON (and Why You'd Want To)

Minification strips every byte of whitespace the JSON parser doesn't need: spaces between tokens, line breaks, indentation. The result is a single-line file that's 20-40% smaller than the pretty-printed version.

Minify savings on common JSON sizes

SourcePretty-printedMinifiedSaved% Reduction
package.json (small project)847 bytes612 bytes23527.7%
tsconfig.json (typical)1,247 bytes918 bytes32926.4%
API response (100 records)187 KB132 KB55 KB29.4%
Public API payload (10K records)18.4 MB12.7 MB5.7 MB31.0%
Typical average~25-35%~30%

Minified JSON is what production APIs send over the wire. Every byte matters when you're serving millions of requests: smaller payloads = faster page loads, lower bandwidth bills, and lower CDN egress costs. Cloudflare, Fastly, and Vercel all charge per GB egress — a 30% reduction on a high-traffic API can save thousands of dollars per month.

When NOT to minify: Don't minify config files you or your team edit by hand. package.json, tsconfig.json, .eslintrc.json — keep these pretty-printed for readability. Minify only the JSON that ships to production (API responses, build outputs, cached data files).

JSON vs JSON5 vs JSONC: What's the Difference?

JSON has a strict spec, but real-world config files often want a few of the things JSON forbids (comments, trailing commas, single quotes). Three formats address this:

FeatureJSON (RFC 8259)JSON5JSONC (JSON with Comments)
Double-quoted keysRequiredOptional (unquoted OK)Required
Single-quoted stringsNot allowedAllowedNot allowed
Trailing commasNot allowedAllowedAllowed
Comments (// and /* */)Not allowedAllowedAllowed (// only)
Hex numbers (0xFF)Not allowedAllowedNot allowed
Infinity, -Infinity, NaNNot allowedAllowedNot allowed
Used byEvery API, every databaseBabel, Postman, VS Code (some)VS Code settings.json, tsconfig.json
Production-safeYes (universal)No (must convert to JSON)No (must convert to JSON)

JSON5 and JSONC are great for human-edited config files because they're forgiving. The tradeoff: no production API accepts them. If you write a .babelrc in JSON5, Babel converts it to strict JSON internally before doing anything with it. If you write settings.json in JSONC for VS Code, VS Code strips the comments before applying them. So JSON5/JSONC inputs always need a one-time conversion before they reach an API.

Our JSON Editor handles both directions: paste JSON5 or JSONC, get strict JSON out (or vice versa). Use the format toggle in the toolbar.

JSON Schema: The Gold Standard for Validation

JSON's built-in validation only catches syntax errors (broken structure, wrong quotes, missing brackets). For serious validation — checking that an object has the right fields, the right types, the right value ranges — you need JSON Schema, a separate specification (current version: 2020-12).

What JSON Schema can validate that a basic parser can't

  • Required fields — "this object MUST have a name field"
  • Field types — "age must be an integer between 0 and 150"
  • String formats — "email must match email format", "birthday must be ISO date"
  • Array constraints — "items must have 1-100 entries, each with a unique id"
  • Enum values — "status must be one of: active, inactive, pending"
  • Nested structures — "address.country must be a 2-letter ISO country code"
  • Conditional rules — "if type is business, then tax_id is required"

Example: a JSON Schema for a user object

{ "$schema": "https://json-schema.org/draft/2020-12/schema", "type": "object", "required": ["name", "email", "age"], "properties": { "name": { "type": "string", "minLength": 1 }, "email": { "type": "string", "format": "email" }, "age": { "type": "integer", "minimum": 0, "maximum": 150 }, "active": { "type": "boolean", "default": true }, "roles": { "type": "array", "items": { "type": "string", "enum": ["admin", "user", "guest"] }, "minItems": 1 } } }

Run any user JSON through a JSON Schema validator (Ajv is the most popular JavaScript implementation) and it reports exactly which fields are wrong and why. JSON Schema is the foundation of OpenAPI (the spec that drives Swagger), AWS API Gateway input validation, and most major API frameworks. If you're building or consuming an API and care about data integrity, learn JSON Schema.

For a deep dive, see the official JSON Schema site and the Ajv validator docs.

7 Strategies for Working With JSON Safely

  1. Always validate before you trust. Never assume JSON from an API, a config file, or a user upload is valid. Run it through a JSON validator first. A single malformed character breaks the entire parse — there's no partial recovery.
  2. Use a browser-based formatter for sensitive data. If the JSON contains API keys, customer data, or PII, only paste it into tools that run entirely in your browser (no upload). Look for explicit "no upload" or "100% private" statements. Our JSON Editor is browser-only.
  3. Pretty-print for editing, minify for production. Keep the human-edited version readable. Minify only the version that ships to users or gets cached. Two files, two purposes.
  4. Sort keys before committing JSON to version control. Sorted JSON produces smaller, more readable diffs when keys change. Use a tool like jq -S or our JSON Editor's "sort keys" toggle.
  5. Convert JSON to TypeScript interfaces early. Once your JSON shape stabilizes, generate matching TypeScript interfaces and use them throughout your code. The compiler will catch every type mismatch for free. Our JSON to TypeScript Converter does this in one click.
  6. Use JSON Schema for API contracts. Define the expected shape of every request and response with JSON Schema. Validate inputs and outputs at the API boundary. This catches 80%+ of data bugs before they reach the database.
  7. When in doubt, diff it. When two JSON files should be equal but aren't, use a JSON diff tool to see exactly what changed. Better than eyeballing 5,000 lines of formatted JSON.

Converting JSON to TypeScript (1-Click)

The fastest way to get from JSON to TypeScript code: paste your JSON into a converter, and it auto-generates matching TypeScript interfaces with proper types for every field. The conversion handles every edge case:

Type mapping: JSON → TypeScript

JSON valueTypeScript typeExample
Stringstring"Alex"name: string
Integer / decimalnumber30age: number
Booleanbooleantrueactive: boolean
NullnullnullmiddleName: null
Array of primitivesT[]["a", "b"]tags: string[]
Array of objectsInterfaceName[][{...}, {...}]items: Item[]
Nested objectSeparate interfaceaddress: {...}address: Address

Worked example: real JSON → real TypeScript

Input JSON:

{ "id": 1, "name": "Alex Chen", "email": "alex@example.com", "active": true, "roles": ["admin", "user"], "address": { "street": "123 King St", "city": "Toronto", "country": "CA", "postal": "M5V 1A1" } }

Generated TypeScript:

interface Address { street: string; city: string; country: string; postal: string; } interface User { id: number; name: string; email: string; active: boolean; roles: string[]; address: Address; }

The converter automatically creates a separate Address interface for the nested object and references it from the parent User interface. Optional fields (those that don't appear in every object) are marked with ?. Use our free JSON to TypeScript Converter to run any conversion.

Frequently Asked Questions

What is a JSON formatter?

A JSON formatter is a tool that takes minified or hard-to-read JSON and outputs pretty-printed JSON with consistent indentation (usually 2 or 4 spaces), proper line breaks, and color-coded syntax. It also validates the JSON at the same time, showing the exact line and character where any syntax error occurs. For example, the input {"name":"Alex","age":30,"city":"Toronto"} formats to a multi-line indented version that's readable at a glance. Use our free JSON Editor to format, validate, minify, and convert JSON to TypeScript in one click.

How do I format JSON online?

To format JSON online for free, paste your JSON into a JSON formatter like our free JSON Editor, click Format, and the tool instantly outputs pretty-printed JSON with consistent 2-space indentation and syntax highlighting. The tool also validates the JSON at the same time, showing the exact line and column of any syntax error. For example, pasting {"name":"Alex","age":30} and clicking Format outputs the same data on 3 indented lines. The whole process takes under 1 second and runs entirely in your browser — no upload required.

How do I validate JSON syntax?

JSON validation is automatic when you format or parse JSON. The validator checks the input against the JSON spec (RFC 8259): proper object/array structure, double-quoted strings, valid number formats, no trailing commas, no comments, and correct nesting. If the input is valid, the formatter outputs pretty-printed JSON. If invalid, the formatter shows the exact line and character where the error occurred plus a plain-English message (e.g., "Unexpected token } at line 12 column 4"). For deeper validation (type checking, required fields), use JSON Schema — a separate spec that defines the expected structure of your JSON.

What is the difference between JSON and JSON5?

JSON5 is an unofficial superset of JSON that adds features missing from the original spec: comments (single-line // and multi-line /* */), single-quoted strings, unquoted object keys, trailing commas, and the +Infinity / -Infinity / NaN number values. JSON5 is popular for config files (Babel, ESLint, VS Code settings) where developer ergonomics matter more than strict spec compliance. The tradeoff: most production APIs only accept strict JSON, so JSON5 inputs need to be converted to valid JSON before being sent. Use our free JSON Editor to format, validate, and convert JSON between formats.

What is JSON Schema?

JSON Schema is a separate specification (currently draft 2020-12) that lets you describe the expected structure of a JSON document. You write a "schema" that says "this object should have a name field (string), an age field (integer, 0-150), and an optional email field (string, email format)". Then a validator like Ajv checks any JSON document against the schema and reports exactly which fields are wrong. JSON Schema is used by OpenAPI, AWS API Gateway, and most major API frameworks to enforce input/output contracts. It's the gold standard for serious API validation — far more thorough than just checking parse-time syntax.

How do I minify JSON?

JSON minification removes all whitespace, line breaks, and indentation from a JSON document, producing a single-line output that's typically 20-40% smaller than the pretty-printed version. Minified JSON is what production APIs send over the wire because smaller payloads = faster transfers and lower bandwidth costs. To minify JSON, paste your pretty-printed JSON into a JSON formatter, click Minify, and copy the single-line output. For example, a 1,247-byte pretty-printed JSON config typically minifies to about 830 bytes. Use our free JSON Editor to minify with one click — it also formats, validates, and converts to TypeScript.

How do I convert JSON to TypeScript?

To convert JSON to TypeScript interfaces, paste your JSON into a converter, and the tool auto-generates matching TypeScript code with proper types for every field. String values become string, numbers become number, booleans become boolean, nulls become null, arrays become T[], and nested objects become separate interfaces. Optional fields are marked with ? based on whether they appear consistently across your JSON. For example, {"name":"Alex","age":30,"active":true} converts to: interface User { name: string; age: number; active: boolean; }. Use our free JSON to TypeScript Converter to run any conversion.

Is it safe to paste sensitive JSON into an online formatter?

It depends on the tool. Browser-based formatters like our free JSON Editor run entirely in your browser — your data never leaves your device, so it's safe to paste API keys, passwords, customer data, or any other sensitive JSON. Server-based formatters (where you click Format and the result comes back from a remote server) should never be used with sensitive data because your JSON gets uploaded to a third party. Look for tools that explicitly say "no upload", "runs in your browser", or "100% private". If a formatter asks you to sign up, upload, or pay, it's almost certainly a server-based tool.

Format, Validate, and Convert JSON — Free

Use our free JSON Editor to format, validate, minify, and convert JSON to TypeScript in one click. Runs entirely in your browser — no upload, no signup, 100% private.

Open JSON Editor →

Related Developer Tools & Guides

JSON Editor JSON to TypeScript CSV ↔ JSON UUID Generator Regex Tester JSON Diff Tool
← Back to Blog