How to Format Large JSON Files

Online JSON formatters work great for small files. But for large JSON — API exports, database dumps, log files — you need the right tool for the file size. This guide covers every approach from browser to command line.

Choose the Right Tool by File Size

< 1 MB

Online JSON Formatter

Use this site — instant results, no setup

Use tool →
1 MB – 10 MB

Online JSON Formatter

Still works fine in modern browsers with enough RAM

Use tool →
10 MB – 100 MB

VS Code or jq CLI

Browser may struggle. Use VS Code Format Document or jq on the command line

> 100 MB

Command-line tools only

Use jq, Python json.tool, or Node.js for streaming parsers

jq — The Best CLI Tool for Large JSON

jq is a lightweight, fast JSON processor for the command line. It handles multi-gigabyte files without loading everything into memory at once.

# Install
brew install jq          # macOS
sudo apt install jq      # Ubuntu/Debian
winget install jqlang.jq # Windows

# Pretty-print a JSON file
jq . large.json

# Save formatted output
jq . large.json > formatted.json

# Compact (minify)
jq -c . large.json > minified.json

# Extract a nested field
jq '.users[0].name' large.json

# Count array items
jq '.users | length' large.json

# Format and validate (exit code 0 = valid)
jq empty large.json && echo "Valid JSON"

Python — Built-in json.tool

# Format in place (overwrites file)
python3 -m json.tool large.json > formatted.json

# With custom indentation
python3 -m json.tool --indent 4 large.json

# Validate only (no output)
python3 -m json.tool large.json > /dev/null && echo "Valid"

# Python script for more control
import json

with open("large.json", "r") as f:
    data = json.load(f)

with open("formatted.json", "w") as f:
    json.dump(data, f, indent=2, sort_keys=True)

Node.js — One-liner

# Format a JSON file using Node.js
node -e "
const fs = require('fs');
const data = JSON.parse(fs.readFileSync('large.json', 'utf8'));
fs.writeFileSync('formatted.json', JSON.stringify(data, null, 2));
console.log('Done');
"

# One-liner (pipe)
cat large.json | node -e "
process.stdin.resume();
let d='';
process.stdin.on('data',c=>d+=c);
process.stdin.on('end',()=>console.log(JSON.stringify(JSON.parse(d),null,2)));
" > formatted.json

VS Code — Format Document

1

Open the JSON file in VS Code

2

Press Alt+Shift+F (Windows/Linux) or Shift+Option+F (Mac) to Format Document

3

Or right-click → Format Document

4

VS Code uses the built-in JSON language server which handles large files well

FAQ

What is the size limit for online JSON formatters?expand_more

Most browser-based JSON formatters handle files up to a few megabytes comfortably. Files larger than 10–20MB may cause the browser to slow down or freeze because JavaScript parses the entire file into memory. For files over 10MB, use a command-line tool like jq or Python.

How do I format a large JSON file on the command line?expand_more

Use jq: cat large.json | jq . > formatted.json. Or with Python: python3 -m json.tool large.json formatted.json. Both are free, handle very large files efficiently, and produce properly indented JSON output.

How do I open a large JSON file in VS Code?expand_more

VS Code handles large files but may warn about file size. Right-click the file in the editor and select "Format Document" (Alt+Shift+F) to pretty-print it. For very large files (>50MB), VS Code disables some features but still opens the file.

Format Large JSON Files — Beautify Big JSON Online