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
VS Code or jq CLI
Browser may struggle. Use VS Code Format Document or jq on the command line
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.jsonVS Code — Format Document
Open the JSON file in VS Code
Press Alt+Shift+F (Windows/Linux) or Shift+Option+F (Mac) to Format Document
Or right-click → Format Document
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.
Part of the JSON Toolkit
Explore All JSON Tools
Free online tools for every JSON task — format, validate, convert, compare, and more.