JSON Formatter — Beautify, Minify & Validate JSON Online

Format, validate, and minify JSON instantly in your browser

Format JSON

Paste JSON to format, minify, validate, or explore as a tree. Syntax highlighting, line numbers, and real-time stats. All processing runs in your browser -- nothing is sent to a server.

Indent
Input
Output
Formatted output will appear here
Privacy: All formatting, validation, and tree building runs entirely in your browser. No data is sent anywhere. Works offline.

Examples

Minified -> Formatted

Input (minified, 94 characters):

{"users":[{"name":"Alice","age":28,"role":"admin"},{"name":"Bob","age":34,"role":"editor"}]}

Output (formatted with 2-space indent):

{
  "users": [
    {
      "name": "Alice",
      "age": 28,
      "role": "admin"
    },
    {
      "name": "Bob",
      "age": 34,
      "role": "editor"
    }
  ]
}

API Response Example

A typical API response before and after formatting:

{"status":"ok","data":{"id":42,"created":"2025-01-15T10:30:00Z","items":[1,2,3]},"meta":{"page":1,"total":100}}

Formatted:

{
  "status": "ok",
  "data": {
    "id": 42,
    "created": "2025-01-15T10:30:00Z",
    "items": [1, 2, 3]
  },
  "meta": {
    "page": 1,
    "total": 100
  }
}

Edge Case -- Empty and Nested Structures

{"empty_object":{},"empty_array":[],"nested":{"a":{"b":{"c":"deep"}}},"mixed":[1,"two",true,null]}

Formatted:

{
  "empty_object": {},
  "empty_array": [],
  "nested": {
    "a": {
      "b": {
        "c": "deep"
      }
    }
  },
  "mixed": [1, "two", true, null]
}

Common JSON Syntax Errors

JSON follows strict syntax rules defined in RFC 8259. These are the most frequent mistakes:

Error Wrong Correct
Single quotes {'name': 'John'} {"name": "John"}
Trailing comma {"a": 1, "b": 2,} {"a": 1, "b": 2}
Unquoted keys {name: "John"} {"name": "John"}
Comments {"a": 1} // note {"a": 1}
Undefined value {"a": undefined} {"a": null}
Missing comma {"a": 1 "b": 2} {"a": 1, "b": 2}

What Is JSON?

JSON (JavaScript Object Notation) is a lightweight text format for structuring data. It was originally derived from JavaScript syntax but is now language-independent -- virtually every programming language has a JSON parser. JSON is defined in RFC 8259.

A JSON document is either an object (key-value pairs wrapped in {}) or an array (ordered values wrapped in []). Values can be strings, numbers, booleans, null, objects, or arrays -- and they can nest to any depth.

JSON is the default data format for REST APIs, configuration files (like package.json, tsconfig.json), NoSQL databases (MongoDB, CouchDB), and inter-service communication. Its simplicity and universal support make it the most widely used data interchange format on the web.

Common Use Cases for a JSON Formatter

  • Debugging API responses: API endpoints often return minified JSON. Formatting it reveals the structure at a glance -- making it easy to inspect nested objects, find missing fields, and verify data types.
  • Reviewing configuration files: Tools like ESLint, Prettier, TypeScript, and VS Code use JSON config files. Formatting them helps you spot errors and understand settings without guessing at indentation.
  • Validating data exports: When exporting data from databases or services, formatting the JSON first catches syntax issues before you feed it into another system.
  • Cleaning up log output: Application logs often include stringified JSON objects. Formatting them makes debugging production issues much faster.
  • Preparing API request bodies: When building or testing POST/PUT requests, formatting the JSON payload makes it easier to verify the structure before sending.
  • Minifying for production: Removing whitespace from JSON payloads reduces transfer size by 10-30%, which matters for mobile clients and high-traffic APIs.
  • Documentation and sharing: Formatted JSON with consistent indentation is easier for teammates to read in pull requests, documentation, and Slack messages.

When to Format vs. Minify JSON

  • Format (beautify) when you need to read, debug, or edit JSON. Indented JSON makes nested structures visible at a glance -- useful for reviewing API responses, config files, and log output.
  • Minify when you need to reduce size for storage or transmission. Removing whitespace can shrink JSON files by 10-30% depending on nesting depth. This matters for API payloads, configuration transfer, and embedded data.

Both operations produce identical data. Only whitespace changes -- no values are modified.

JSON Data Types

JSON supports six value types:

Type Example Notes
String "hello world" Must use double quotes. Supports escape sequences like \n, \t, \"
Number 42, 3.14, -1, 2.5e10 No leading zeros. No hex/octal. Supports scientific notation
Boolean true, false Lowercase only. True and TRUE are invalid
Null null Lowercase only. Represents absence of a value
Array [1, "two", true] Ordered list. Items can be any type, including mixed
Object {"key": "value"} Unordered key-value pairs. Keys must be strings

JSON vs. Other Data Formats

Feature JSON XML YAML CSV
Readability Good Verbose Excellent Good (flat data)
Comments No Yes Yes No (standard)
Nesting support Yes Yes Yes No
Parsing speed Fast Slow Medium Fast
Common use APIs, config Legacy systems Config files Tabular data
Native in browsers Yes Yes (DOM) No No

JSON is the standard exchange format for web APIs because of its simplicity, fast parsing, and native support in JavaScript and most modern languages.

Frequently Asked Questions

What does a JSON formatter do?

A JSON formatter takes raw or minified JSON and adds consistent indentation and line breaks so the structure is easy to read. It also validates JSON syntax and reports errors if the input is not valid. This is useful for debugging API responses, reviewing configuration files, and working with data exports.

What is the difference between formatting and minifying JSON?

Formatting (beautifying) adds indentation and line breaks to make JSON human-readable. Minifying removes all unnecessary whitespace to reduce file size. Both produce valid JSON -- the data is identical, only the whitespace changes. Use formatting for readability and minifying for transmission or storage.

What indentation should I use for JSON?

2 spaces and 4 spaces are both common. 2 spaces keeps files compact and is used by many JavaScript/TypeScript style guides and tools like Prettier. 4 spaces provides more visual separation and is common in Python projects. Tabs are less typical for JSON but work fine. The choice is a preference -- the parsed data is identical.

What causes "Unexpected token" errors in JSON?

Common causes: single quotes instead of double quotes, trailing commas after the last item in an array or object, unquoted property names, comments (JSON does not support comments), and undefined instead of null. JSON requires strict syntax -- all keys and string values must use double quotes.

Can JSON contain comments?

No. The JSON specification (RFC 8259) does not allow comments. If you need comments in configuration files, consider JSONC (JSON with Comments, used by VS Code and TypeScript), JSON5, or YAML. Standard JSON parsers will reject input containing // or /* */ comments.

Is there a size limit for JSON?

The JSON specification has no size limit. In practice, browser-based tools are limited by available memory -- this formatter handles files up to several megabytes comfortably. For very large files (100 MB+), use a command-line tool like jq or python -m json.tool.

Why is my JSON invalid even though it looks correct?

Common invisible issues: a BOM (byte order mark) at the start of the file, invisible Unicode characters (like zero-width spaces), curly quotes ("smart quotes") instead of straight quotes, or a missing comma between items. Paste the JSON into a plain text editor first to strip hidden characters.

What is the difference between JSON and a JavaScript object?

JSON is a text format with strict rules. JavaScript objects are in-memory data structures with looser syntax. Key differences: JSON requires double-quoted keys, does not allow functions or undefined, does not support trailing commas or comments, and cannot contain special values like NaN or Infinity. JSON.parse() converts JSON text to a JavaScript object; JSON.stringify() converts an object to JSON text.

Does this tool send my data to a server?

No. All formatting, minifying, and validation runs entirely in your browser using JavaScript. No data is transmitted over the network. You can disconnect from the internet and the tool works identically.

How do I format JSON from the command line?

Common options: cat file.json | python -m json.tool (Python, built-in), cat file.json | jq . (jq, fast and powerful), or node -e "process.stdin.resume(); var d=''; process.stdin.on('data',c=>d+=c); process.stdin.on('end',()=>console.log(JSON.stringify(JSON.parse(d),null,2)))" (Node.js). For most use cases, jq is the standard tool.

What is JSON used for?

JSON is the standard data exchange format for web APIs, configuration files, data storage, and inter-service communication. REST APIs almost universally use JSON for request and response bodies. Configuration files like package.json, tsconfig.json, and .eslintrc.json use JSON. NoSQL databases like MongoDB store documents in a JSON-like format (BSON). It is supported natively by all modern programming languages.

How do I fix trailing comma errors in JSON?

Remove the comma after the last item in any array or object. For example, {"a": 1, "b": 2,} should become {"a": 1, "b": 2}. Trailing commas are allowed in JavaScript and TypeScript, which is why they appear frequently -- but strict JSON does not permit them. Many code editors (VS Code, Sublime Text) can highlight these automatically.

What is JSONC and how does it differ from JSON?

JSONC (JSON with Comments) is a superset of JSON that allows // single-line and /* */ multi-line comments, plus trailing commas. It is used by VS Code for settings files (settings.json) and by TypeScript for tsconfig.json. JSONC is not valid JSON -- standard JSON parsers will reject it. If you need to convert JSONC to valid JSON, strip the comments and trailing commas first.

Does JSON preserve key order?

The JSON specification says objects are "unordered" collections of key-value pairs. In practice, most implementations (JavaScript, Python, Go, Java) preserve insertion order, and JSON.stringify() outputs keys in the order they were added. However, you should not depend on key order for correctness -- treat JSON objects as unordered maps.

Privacy & Limitations

  • Client-side only. No data is sent to any server. No cookies, no tracking of pasted content.
  • Size limits. Browser-based processing works well for files up to a few megabytes. For very large JSON, use a command-line tool.
  • Formatting only. This tool reformats whitespace and validates syntax. It does not modify values, reorder keys, or perform schema validation.

Related Tools

Related Tools

View all tools

JSON Formatter FAQ

What does a JSON formatter do?

A JSON formatter takes raw or minified JSON and adds consistent indentation and line breaks so the structure is easy to read. It also validates the JSON syntax and reports errors if the input is not valid JSON.

What is the difference between formatting and minifying JSON?

Formatting (beautifying) adds indentation and line breaks to make JSON human-readable. Minifying removes all unnecessary whitespace to reduce file size. Both produce valid JSON — the data is identical, only the whitespace changes.

Is this JSON formatter safe to use with sensitive data?

Yes. All processing runs entirely in your browser using JavaScript. Your JSON is never sent to any server. You can verify this by disconnecting from the internet — the tool works identically offline.

What causes 'Unexpected token' errors in JSON?

Common causes include: single quotes instead of double quotes, trailing commas after the last item, unquoted property names, comments (JSON does not support comments), and using undefined instead of null. JSON requires strict syntax — keys and string values must use double quotes.

What indentation should I use for JSON?

2 spaces and 4 spaces are the most common conventions. 2 spaces keeps files compact and is used by many JavaScript style guides. 4 spaces provides more visual separation and is common in Python projects. Tabs are less common for JSON. The choice is a matter of preference — the data is the same regardless of indentation.

Can JSON contain comments?

No. The JSON specification (RFC 8259) does not allow comments. If you need comments in configuration files, consider JSON5, JSONC (JSON with Comments, used by VS Code), or YAML. Standard JSON parsers will reject input containing comments.

What is the maximum size of a JSON file?

The JSON specification has no size limit. In practice, browser-based tools like this one are limited by available memory. This formatter handles files up to several megabytes comfortably. For very large files (100MB+), use a command-line tool like jq.

Why is my JSON invalid even though it looks correct?

Common invisible issues include: a BOM (byte order mark) at the start of the file, invisible Unicode characters, curly quotes (smart quotes) instead of straight quotes, or a missing comma between items. Try pasting the JSON into a plain text editor first to strip hidden characters.

What is the difference between JSON and a JavaScript object?

JSON is a text format with strict rules — double-quoted keys, no functions, no trailing commas, no comments. JavaScript objects are in-memory data structures with looser syntax. JSON.parse() converts JSON text to a JavaScript object; JSON.stringify() converts an object to JSON text.

How do I format JSON from the command line?

Use jq: 'cat file.json | jq .' or Python: 'python -m json.tool file.json'. jq is the standard command-line JSON processor — it formats, filters, and transforms JSON. Both are available on most systems or easy to install.

What is JSON used for?

JSON (JavaScript Object Notation) is the standard data exchange format for web APIs, configuration files, data storage, and inter-service communication. It is supported natively by all modern programming languages and is the default format for REST APIs.

How do I fix trailing comma errors in JSON?

Remove the comma after the last item in any array or object. For example, change {"a": 1, "b": 2,} to {"a": 1, "b": 2}. Trailing commas are allowed in JavaScript but not in JSON. Many editors and linters can detect these automatically.

Request a New Tool
Improve This Tool