How to Format JSON in VS Code (and Speed Up Your Workflow)
The built-in shortcut
VS Code formats JSON natively, no extension required. Open any .json file and press:
- Mac:
Shift+Option+F - Windows / Linux:
Shift+Alt+F
That's it. The file is reformatted with two-space indentation by default.
Format on save
To format every JSON file automatically when you save:
- Open settings (
Cmd/Ctrl+,) - Search for Format On Save
- Tick the box
For more control, edit settings.json:
{
"[json]": {
"editor.defaultFormatter": "vscode.json-language-features",
"editor.formatOnSave": true,
"editor.tabSize": 2
},
"[jsonc]": {
"editor.formatOnSave": true,
"editor.tabSize": 2
}
}
Format pasted JSON automatically
Add this to settings.json:
{ "editor.formatOnPaste": true }
Now every time you paste minified JSON, VS Code pretty-prints it instantly.
Working with very large JSON files
VS Code's editor struggles past ~50MB. For huge files:
- Disable language features for that file —
Ctrl/Cmd + Shift + P→ "Change Language Mode" → "Plain Text" - Use a streaming tool —
jq,fx, or pipe throughpython -m json.tool - Use JSONNeat in your browser — it handles multi-megabyte files smoothly without VS Code's overhead
Useful extensions
- JSON Tools (eriklynd) — minify, escape, sort keys
- Paste JSON as Code (quicktype) — generates TypeScript / Go / Rust types from a JSON sample
- JSON Crack — visualize JSON as an interactive graph
- Rainbow Brackets — makes nested JSON readable at a glance
Keyboard shortcuts cheat sheet
| Action | Mac | Windows / Linux |
|---|---|---|
| Format document | Shift+Option+F | Shift+Alt+F |
| Format selection | Cmd+K Cmd+F | Ctrl+K Ctrl+F |
| Fold all | Cmd+K Cmd+0 | Ctrl+K Ctrl+0 |
| Unfold all | Cmd+K Cmd+J | Ctrl+K Ctrl+J |
| Find in file | Cmd+F | Ctrl+F |
When VS Code can't help: invalid JSON
If your file has syntax errors, VS Code's formatter refuses to run. Paste it into JSONNeat's validator — it reports the exact line and column of the first error so you can fix it and reformat.
Try the tools: JSON Formatter · Validator · Minifier