How to format JSON without changing its data

JSON formatting adds indentation and line breaks outside strings so nested objects and arrays become easier to read while the represented values stay intact.

Open the JSON Formatter

What JSON formatting changes

A formatter changes whitespace outside strings. It can place object members and array items on separate lines and indent each nesting level. Spaces inside string values remain data and must not be changed.

The ToolPixels formatter preserves number spellings, large integer text, key order, duplicate keys, and escape sequences. It does not sort keys or repair invalid input.

How to format JSON

  1. Paste JSON or open a JSON file.
  2. Choose two spaces, four spaces, or tabs.
  3. Select Format JSON.
  4. If an error appears, jump to the reported location and correct the syntax.
  5. Copy or download the formatted result.

Use two spaces when compact diffs matter and four spaces when deeper visual separation is helpful. Follow the repository's existing convention.

A JSON formatting example

Input

{"name":"ToolPixels","tags":["web","tools"]}

Two-space output

{
  "name": "ToolPixels",
  "tags": [
    "web",
    "tools"
  ]
}

Valid JSON rules to remember

  • Property names and strings use double quotes.
  • Members and array items need commas, but the final item cannot have a trailing comma.
  • Comments are not part of standard JSON.
  • undefined, NaN, and Infinity are invalid.
  • Top-level strings, numbers, booleans, and null are valid JSON too.

Formatting, minifying, and validating

ActionResult
FormatAdd readable whitespace
MinifyRemove unnecessary whitespace
ValidateCheck syntax and report the first error

None of these checks whether the values meet an application's business rules. Use JSON Schema or application validation for that.

Try it with ToolPixels

Format, minify, or validate JSON in the browser without uploading the document.

Format JSON now