> format | validate | minify <

// Format, validate, and minify JSON data instantly

[FORMAT]

Pretty Print

Beautify JSON with customizable indentation. Choose 2 spaces, 4 spaces, or tabs for perfect formatting.

[MINIFY]

Compact Output

Minify JSON by removing all whitespace. Reduce file size for production deployments and API responses.

[VALIDATE]

Syntax Check

Validate JSON syntax instantly. Get detailed error messages with line and position information.

// ABOUT JSON FORMATTING

What is JSON:

JSON (JavaScript Object Notation) is a lightweight data interchange format defined by RFC 8259. It is easy for humans to read and write, and easy for machines to parse and generate. JSON is built on two structures: objects (key-value pairs) and arrays (ordered lists).

Example:

{"name":"John","age":30} → {\n "name": "John",\n "age": 30\n}

Common Use Cases:

  • >API response debugging and inspection
  • >Configuration file formatting
  • >Data validation before processing
  • >Reducing payload size with minification
  • >Sorting keys for consistent output

>> frequently asked questions

Q: What is a JSON formatter?

A: A JSON formatter (also called JSON beautifier or pretty printer) takes raw or minified JSON data and reformats it with proper indentation and line breaks, making it human-readable and easier to debug.

Q: What is the difference between prettify and minify?

A: Prettify (format) adds indentation, line breaks, and spaces to make JSON readable. Minify removes all unnecessary whitespace to reduce file size, which is ideal for production use and API transmission.

Q: How does JSON validation work?

A: JSON validation checks whether the input conforms to the JSON specification (RFC 8259). It verifies proper syntax including matching brackets, correct quoting of keys and strings, valid data types, and proper use of commas and colons.

Q: What does sorting keys do?

A: Sorting keys alphabetically reorders all object keys in the JSON structure. This is useful for comparing JSON objects, creating deterministic output, and maintaining consistency across different environments.

Q: How does JSON compare to YAML?

A: JSON uses braces and brackets with strict syntax, while YAML uses indentation-based formatting. JSON is more widely supported in APIs and programming languages. YAML is more human-readable but more complex to parse. Both represent the same data structures. If you need to convert between them, see our JSON to YAML converter.

Q: How do I format JSON online?

A: Paste your JSON into the INPUT area and click [FORMAT]. The tool validates the syntax and pretty prints it with your chosen indentation (2 spaces, 4 spaces, or tab). Everything runs locally in your browser using JSON.parse and JSON.stringify — your JSON is never sent to a server, so it is safe to format production API responses, tokens, or any sensitive data.

Q: What is the difference between format, beautify, prettify, and pretty print?

A: These are four names for the same operation — converting compact or minified JSON into an indented, multi-line, human-readable form. Format is the generic IDE term (VS Code, IntelliJ). Beautify was popularized by web tools. Prettify and pretty print come from the programming community, e.g. JSON.stringify(obj, null, 2) or Python's json.dumps(indent=2). The underlying data is unchanged; only the whitespace differs.

Q: What indentation should I use — 2 spaces, 4 spaces, or tabs?

A: There is no single correct answer, but 2 spaces is the most common default (used by npm, JSON.stringify's default pretty print, and most REST API documentation). 4 spaces is preferred in Python-heavy environments. Tabs are sometimes chosen because they produce smaller file sizes and render differently in each editor. Pick whichever your team and existing files already use, and stay consistent.

Q: How do I minify JSON?

A: Paste your JSON and click [MINIFY]. Minification removes every optional whitespace character — spaces, tabs, newlines — producing the shortest valid JSON. A typical payload shrinks 30–60%. Use minified JSON for production API responses and network transmission; format/prettify only when you need to read or diff the data. Programmatically: JSON.stringify(obj) (no indent argument) in JavaScript or json.dumps(obj, separators=(',', ':')) in Python.

Q: Why is my JSON invalid?

A: The most common JSON syntax errors are:
Trailing comma after the last item ({"a": 1,}) — not allowed in strict JSON
Single quotes instead of double quotes ({'a': 1}) — JSON requires "
Unquoted keys ({a: 1}) — object keys must be quoted strings
Comments (// ... or /* ... */) — the JSON spec forbids comments (see JSONC for a comment-friendly superset)
Undefined, NaN, or Infinity — JSON values must be null, a number, string, boolean, array, or object
Duplicate keys — technically allowed by RFC 8259 but behavior is parser-dependent
Our validator reports the exact line and column of the first error.

Q: Is this JSON formatter safe for sensitive data?

A: Yes. All parsing, formatting, minifying, and validation happens entirely in your browser using the built-in JSON.parse and JSON.stringify APIs. Your JSON never leaves the tab — it is not uploaded, logged, or transmitted. You can safely format JWTs, API credentials, configuration with secrets, or any confidential payload.

Q: How do I format JSON in code?

A: Every major language has a built-in formatter:
JavaScriptJSON.stringify(obj, null, 2)
Pythonjson.dumps(obj, indent=2, sort_keys=True)
PHPjson_encode($obj, JSON_PRETTY_PRINT)
Gojson.MarshalIndent(obj, "", " ")
RubyJSON.pretty_generate(obj)
Shell (jq)cat file.json | jq '.' to format, jq -c '.' to minify

Q: What is JSON5 / JSONC and how does it relate to JSON?

A: JSON5 is a superset of JSON that allows comments, trailing commas, unquoted keys, and single-quoted strings. JSONC (JSON with Comments) is a lighter superset used by VS Code configuration files that adds only // and /* */ comments. Neither is valid under RFC 8259 — if your consumer expects standard JSON, our formatter will reject these extensions. Convert them to strict JSON first by removing comments and trailing commas.

Q: What is the difference between a JSON formatter and a JSON parser?

A: A parser converts a JSON string into an in-memory data structure (objects, arrays, strings, numbers) you can manipulate programmatically. A formatter is a display-layer tool that takes JSON and re-emits it with cosmetic changes (indentation, key ordering). Every formatter internally parses and then serializes — the parse step is what validates the syntax and catches errors.

// OTHER LANGUAGES