ConvertCaseTool
Development7 min read

How to Format JSON: A Complete Guide for Developers

JSON (JavaScript Object Notation) is the most common data format on the web. But compact JSON is nearly impossible to read. This guide covers everything you need to know about formatting, validating, and working with JSON.

What Is JSON Formatting?

JSON formatting (also called "pretty printing" or "beautifying") transforms compact, minified JSON into structured, indented text that humans can easily read. For example:

Minified (hard to read):

{"name":"John","age":30,"address":{"city":"NYC","zip":"10001"}}

Formatted (easy to read):

{
  "name": "John",
  "age": 30,
  "address": {
    "city": "NYC",
    "zip": "10001"
  }
}

How to Format JSON Online

  1. Go to our JSON Formatter
  2. Paste your JSON in the input panel
  3. Click "Beautify" for formatted output or "Minify" to compress
  4. Copy or download the result

Common JSON Syntax Errors

  • Trailing commas: {"a":1,} — remove the last comma
  • Single quotes: {'a':1} — JSON requires double quotes
  • Unquoted keys: {a:1} — keys must be quoted strings
  • Comments: JSON does not support // or /* */ comments

JSON Formatting in Code

JavaScript

JSON.stringify(data, null, 2)  // 2-space indent
JSON.stringify(data)          // minified

Python

import json
json.dumps(data, indent=2)    # formatted
json.dumps(data)               # minified

Command Line

cat data.json | python -m json.tool   # Python
cat data.json | jq .                  # jq

Related Tools

Format JSON Now

Paste JSON and get formatted, validated output instantly.

Open JSON Formatter →