Back to blog list
Developer Guide

How to Format JSON: A Complete Guide

Quick Summary

To format JSON, parse the dense string and serialize it with indented whitespace (using a browser tool, an IDE like VS Code, or a CLI like jq).

Why Is JSON Formatting Necessary?

When APIs or databases output JSON, they usually strip away all whitespace and line breaks to minimize bandwidth. While this “minified” JSON is optimal for servers, it is practically unreadable for humans.

JSON Formatting (or beautifying) is the process of restoring structure, adding indents (typically 2 or 4 spaces), and organizing brackets onto separate lines so developers can easily review, debug, and read the values.


Method 1: Using Online Browser Tools

For instant validation and styling, browser tools are the fastest path.

  1. Copy your minified JSON.
  2. Go to JSON Formatter Online.
  3. Paste the text.
  4. Select 2 spaces or 4 spaces and click Format.
  5. Your formatted data can be copied or downloaded immediately.

Method 2: Formatting in VS Code (IDE)

If you are writing code in Visual Studio Code, formatting is built-in:

  1. Open your .json file.
  2. Press Shift + Alt + F on Windows, or Option + Shift + F on macOS.
  3. VS Code will automatically pretty-print the document according to your indentation settings.

Method 3: Using the Command Line with jq

For terminal fans or automation bash scripts, jq is the gold standard for formatting JSON:

# Formats a local JSON file and prints to terminal
jq . data.json

# Format string from curl
curl -s https://api.github.com | jq .

Frequently Asked Questions

Does formatting JSON increase file size?

Yes, formatting adds tabs, spaces, and newline characters which increase the total byte count. For production web APIs, always minify your JSON payloads before sending.

Need to work with JSON right now?

Check out our 100% private, fast, browser-based tools.

Open Free JSON Formatter