Just Formatter
← Back to blog

json

How to Format Minified JSON in VS Code, Browser, and CLI

2026-05-277 min read
Try it now — JSON Formatter & ValidatorOpen full screen →

Why JSON gets minified and when you need to expand it

Minified JSON is JSON with all non-significant whitespace removed. Production APIs transmit minified JSON to reduce payload size — removing spaces, newlines, and indentation from a large object can cut its size by 15-30%. Build tools minify JSON config files. Log aggregation systems strip whitespace to save storage.

When you need to read, debug, or compare minified JSON, expanding it — pretty-printing with consistent indentation — makes the structure immediately readable. A 500-character minified string becomes a clear 40-line indented document. The right tool depends on where you encounter the JSON and what you want to do with the output.

VS Code: built-in format document

VS Code has a built-in JSON formatter. Open a .json file (or paste the JSON into an Untitled file and save it with a .json extension), then use Format Document: Shift+Alt+F on Windows and Linux, Shift+Option+F on macOS. VS Code formats the JSON in place with 2-space indentation.

For JSON embedded in a JavaScript or TypeScript file (a string literal), select just the JSON content, then use Format Selection: Ctrl+K Ctrl+F (Windows/Linux) or Cmd+K Cmd+F (macOS). This formats only the selected text, leaving the surrounding code untouched.

  • Format entire .json file: Shift+Alt+F (Windows/Linux), Shift+Option+F (macOS)
  • Format selection only: Ctrl+K Ctrl+F (Windows/Linux), Cmd+K Cmd+F (macOS)
  • Change indentation: File → Preferences → Settings → Editor: Tab Size (or per-language in .editorconfig)
  • Prettier extension: installs prettier as the default JSON formatter and adds trailing-comma and bracket-spacing options

Chrome and Firefox DevTools

When an API returns JSON in the browser, DevTools automatically formats it in the Response Preview tab. Open DevTools → Network tab → click a JSON request → Preview. The formatted tree is read-only but navigable — click disclosure triangles to expand/collapse nested objects.

To get the raw formatted JSON text for copying: in Chrome, right-click anywhere in the Preview pane and choose 'Copy response'. In Firefox, click the Response tab (not Preview) for the raw minified text, or use the search field at the top of the JSON tree to find a specific key.

💡

In Chrome DevTools Console, type copy(JSON.parse(document.body.innerText)) on a page that displays raw JSON. This puts the pretty-printed JSON in your clipboard without any wrapping code.

jq — the JSON command-line tool

jq is the standard command-line JSON processor. It installs on macOS via Homebrew (brew install jq), on Linux via apt or yum, and on Windows via Chocolatey or winget. The simplest usage is the identity filter . which pretty-prints and validates JSON:

jq-examples.sh
# Pretty-print a JSON file
jq . minified.json

# Pretty-print JSON from a curl response
curl -s https://api.example.com/data | jq .

# Write pretty output to a new file
jq . minified.json > pretty.json

# Format and extract a specific field
jq '.users[0].name' data.json

# Compact/minify JSON (opposite direction)
jq -c . pretty.json

# Validate without output (exit code 0 = valid)
jq empty minified.json && echo "valid"

jq is the fastest option for files and pipes in a terminal. It also serves as a powerful query tool — you can filter, transform, and reshape JSON in the same command that formats it, making it a essential tool for API debugging in the shell.

Python one-liner

Python ships with a json.tool module that formats JSON from stdin or a file. It is available on any system with Python 3 installed — which is most developer machines and all Linux servers:

python-format.sh
# Format a JSON file (outputs to stdout)
python3 -m json.tool minified.json

# Format from stdin (pipe)
echo '{"a":1,"b":{"c":2}}' | python3 -m json.tool

# Write output to a file
python3 -m json.tool minified.json > pretty.json

# Format with 4-space indent
python3 -m json.tool --indent 4 minified.json

# Sort keys alphabetically
python3 -m json.tool --sort-keys minified.json

# Python one-liner for inline use in scripts
python3 -c "import json,sys; print(json.dumps(json.load(sys.stdin), indent=2))" < minified.json

python3 -m json.tool also validates the JSON as it formats — if the input is invalid, it exits with an error message and a non-zero exit code, making it useful in scripts where you need to both format and verify.

Node.js — scripts and one-liners

Node.js is ubiquitous in JavaScript/TypeScript projects. Both a quick one-liner and a reusable script are easy to write:

formatJson.js
// One-liner from stdin (macOS/Linux)
// node -e "..." < minified.json
node -e "process.stdout.write(JSON.stringify(JSON.parse(require('fs').readFileSync(0,'utf8')),null,2)+'\n')"

// Reusable script: node formatJson.js input.json [output.json]
const fs = require('fs');
const [,, input, output] = process.argv;

const raw = fs.readFileSync(input, 'utf8');
const formatted = JSON.stringify(JSON.parse(raw), null, 2) + '\n';

if (output) {
  fs.writeFileSync(output, formatted, 'utf8');
  console.log(`Formatted: ${input} → ${output}`);
} else {
  process.stdout.write(formatted);
}

Online tools — when you need a quick paste

For one-off formatting during development, online tools are the fastest option — paste minified JSON, get formatted output, copy or download. Just Formatter's JSON Formatter tool formats, validates, and shows the full JSON tree in one step. It also reports the exact line and character of any syntax error, which is useful when the minified string comes from a corrupted source.

Online tools are also useful when you are on a machine where you cannot install software, or when you want to share a formatted JSON snippet with a colleague. Paste the minified JSON, format it, and copy the link to share.

💡

Just Formatter processes all JSON in your browser — the raw content is never sent to a server. This makes it safe for formatting JSON payloads that contain sensitive data like API responses from internal services.