How to Format JSON in IntelliJ: Easy Guide (2026)

Press Ctrl+Alt+L (Windows/Linux) or Cmd+Option+L (Mac) to instantly format any JSON file in IntelliJ IDEA. IntelliJ has built-in JSON formatting with no plugins needed. It handles validation, schema support, and custom formatting rules out of the box.
IntelliJ IDEA's JSON formatter works on files, clipboard content, and code snippets. It automatically detects JSON structure, validates syntax, and applies consistent indentation and spacing. The formatter handles large JSON files (100MB+), nested objects, arrays, and even JSONC (JSON with comments) used in VS Code config files. You can customize indentation width, property alignment, and array formatting in the code style settings.
Beyond basic formatting, IntelliJ validates JSON against schemas, highlights syntax errors in real-time, and provides quick fixes for common issues like trailing commas or unquoted keys. The formatter integrates with IntelliJ's "Format on Save" feature, so JSON files auto-format every time you save. For API responses and configuration files, this saves time and prevents formatting inconsistencies across your project.
How to Format JSON in IntelliJ
Open your JSON file or paste JSON into IntelliJ. Press Ctrl+Alt+L (Windows/Linux) or Cmd+Option+L (Mac). Done.
Before formatting:
{"name":"John","age":30,"skills":["Java","Python"],"active":true}
After formatting:
{
"name": "John",
"age": 30,
"skills": [
"Java",
"Python"
],
"active": true
}
The formatted version shows structure at a glance. You can see nested objects, array items, and property relationships without counting brackets.
Quick Comparison: All Formatting Methods
| Method | Setup time | Works offline | Handles large files | Keyboard shortcut | Best for |
|---|---|---|---|---|---|
| IntelliJ | 0 (built-in) | Yes | 50MB+ | Java developers, daily JSON work | |
| VS Code | 0 (built-in) | Yes | 50MB+ | Multi-language developers | |
| Notepad++ JSTool | 2 minutes | Yes | Up to 5MB | Lightweight editor users | |
| Python json.tool | 0 (if installed) | Yes | 100MB+ | N/A (command line) | Batch processing, huge files |
| Online formatters | 0 | No | Varies | N/A | Quick one-off, no install access |
IntelliJ is the best choice if you already use it for Java development. Zero setup, handles large files smoothly, and integrates with your existing workflow.
Other Ways to Format JSON in IntelliJ
Right-click menu: Right-click anywhere in the JSON file → select "Reformat Code". Same result as the keyboard shortcut.
Format dialog (Ctrl+Shift+Alt+L or Cmd+Shift+Option+L): Opens a dialog with additional options like "Optimize imports" and "Rearrange code". Useful when you want more control over what gets formatted.
Format on paste: IntelliJ can automatically format JSON when you paste it. Go to Settings → Editor → General → Smart Keys → check "Reformat on paste". Now pasted JSON formats automatically.
Most of the time you'll only use Ctrl+Alt+L. The other methods are there when you need them.
Configure JSON Formatting Rules
- Go to Settings/Preferences → Editor → Code Style → JSON
- Adjust indent size, spacing around colons, max line length
- Click Apply → OK → reformat with
Ctrl+Alt+L
Key settings to configure:
- Tab size: Set to 2 or 4 spaces based on your team standards
- Indent: Choose spaces or tabs
- Space after colon: Add space after in key-value pairs (enabled by default)
: - Wrap arrays: Control when arrays wrap to new lines
- Keep blank lines: Preserve intentional blank lines in JSON
Most teams use 2-space indentation for JSON. If your team uses 4 spaces, change "Tab size" to 4 and "Indent" to 4.
Format JSON Automatically on Save
- Settings → Tools → Actions on Save
- Check "Reformat code"
- Optionally check "Optimize imports" and "Rearrange code"
- Click Apply → OK
Now JSON formats automatically every time you save (Ctrl+S or Cmd+S). This is the most convenient option. Your JSON stays formatted without thinking about it.
You can also enable "Run code cleanup" for additional formatting rules. This applies more aggressive formatting like removing trailing spaces and organizing code structure.
JSON Validation and Error Detection
IntelliJ validates JSON syntax in real-time. Errors appear with red underlines. Hover over the error to see the message.
Common JSON syntax errors IntelliJ catches:
Trailing commas (invalid JSON):
{
"name": "John",
"age": 30,
}
IntelliJ highlights the trailing comma with a red underline. Press Alt+Enter (Windows/Linux) or Option+Return (Mac) on the error for a quick fix that removes it.
Single quotes (invalid JSON):
{
'name': 'John'
}
IntelliJ shows an error and can convert to double quotes with Alt+Enter / Option+Return.
Missing commas:
{
"name": "John"
"age": 30
}
IntelliJ indicates where commas are missing with red underlines.
Unmatched brackets:
{
"items": ["a", "b"
}
IntelliJ highlights the mismatched bracket and shows where it expects the closing bracket.
Comments (not valid in strict JSON):
{
// This is a comment
"name": "John"
}
IntelliJ shows an error because standard JSON doesn't allow comments. However, IntelliJ supports JSONC (JSON with Comments) for files like
tsconfig.json.vscode/settings.jsonAdvanced JSON Features in IntelliJ
JSON Schema validation: Go to Settings → Languages & Frameworks → Schemas and DTDs → JSON Schema Mappings to validate against schemas. IntelliJ can auto-detect schemas for common files like
package.jsontsconfig.jsonJSON Path testing: IntelliJ supports JSON Path expressions for extracting data from JSON structures. Use the "Evaluate Expression" feature in the debugger or install the JSON Path plugin for more advanced testing.
Quick navigation (Ctrl+F12 / Cmd+F12): Shows the JSON structure outline. Click any property to jump to it. Useful for navigating large JSON files.
Folding/Unfolding: Click the minus/plus icons in the gutter to collapse or expand JSON objects and arrays. Or use Ctrl+NumPad- to fold and Ctrl+NumPad+ to unfold (Cmd on Mac).
Find in JSON: Use Ctrl+F (Cmd+F on Mac) to search for keys or values. IntelliJ highlights all matches and lets you navigate between them with F3 / Shift+F3.
Formatting Large JSON Files
IntelliJ handles large JSON files better than most editors. It can format files up to 50MB without issues. Above that, you might see slowdowns.
For very large files (100MB+):
- Use a JSON splitter to break the file into smaller chunks
- Format each chunk separately
- Merge them back if needed
Or format via command line with Python's json.tool:
python -m json.tool large.json formatted.json
IntelliJ's indexing and caching make it faster than Notepad++ or basic text editors for large JSON files.
Formatting API Responses
Copy JSON from your browser's Network tab, Postman, or curl output. Create a new file in IntelliJ (Ctrl+N / Cmd+N) or open a scratch file (Ctrl+Shift+Alt+Insert / Cmd+Shift+Option+N). Paste the JSON. IntelliJ auto-detects it as JSON. Press Ctrl+Alt+L / Cmd+Option+L to format.
Scratch files are temporary files that don't save to your project. Perfect for formatting API responses you don't need to keep. Go to File → New → Scratch File → JSON.
Formatting JSON Inside Other Files
Sometimes JSON appears inside Java strings, HTML files (JSON-LD schema), or JavaScript files.
To format embedded JSON:
- Select just the JSON portion (don't include surrounding code)
- Press
Ctrl+Alt+L/Cmd+Option+L - IntelliJ formats only the selected text
IntelliJ's "Format Selection" works better than most editors. It understands context and formats JSON inside strings correctly.
For JSON in Java strings:
String json = "{\"name\":\"John\",\"age\":30}";
Select the JSON part (inside the quotes), press Ctrl+Alt+L, and IntelliJ formats it while preserving the string escaping:
String json = "{\n" +
" \"name\": \"John\",\n" +
" \"age\": 30\n" +
"}";
Batch Formatting Multiple JSON Files
Need to format multiple JSON files at once?
In IntelliJ:
- Select the folder containing JSON files in the Project view
- Right-click → Reformat Code
- Check "Include subdirectories" if needed
- Click Run
IntelliJ formats all JSON files in the selected folder.
Command line with Python:
for file in *.json; do
python -m json.tool "$file" > temp.json && mv temp.json "$file"
done
This works on Linux/Mac. For Windows PowerShell:
Get-ChildItem *.json | ForEach-Object {
python -m json.tool $_.FullName temp.json
Move-Item temp.json $_.FullName -Force
}
Formatting JSON with Comments (JSONC)
Files like
tsconfig.jsonjsconfig.json.vscode/settings.jsonPress Ctrl+Alt+L / Cmd+Option+L and IntelliJ preserves your comments while formatting the structure.
For other files with comments, IntelliJ might show errors. You can either:
- Remove comments, format, add them back
- Change the file type to JSONC in the bottom right corner of the editor
When Formatting Doesn't Work
File not recognized as JSON: Check the bottom right corner of the editor. If it says "Text" instead of "JSON", click it and select JSON from the list.
Shortcut conflict: If Ctrl+Alt+L does nothing, another plugin or system shortcut might be using it. Go to Settings → Keymap → search for "Reformat Code" → check the assigned shortcut. Change it if needed.
Invalid JSON: IntelliJ won't format invalid JSON. Look for red underlines indicating syntax errors. Fix those first, then format.
File too large: IntelliJ might refuse to format files over 100MB. Use command-line tools or split the file first.
Changing Indentation from 2 Spaces to 4
IntelliJ uses 2-space indentation for JSON by default. To change it:
- Settings → Editor → Code Style → JSON
- Change "Tab size" to 4
- Change "Indent" to 4
- Click Apply → OK
- Reformat your JSON with
Ctrl+Alt+L/Cmd+Option+L
The new indentation applies immediately to all future formatting.
Quick navigation: Use Ctrl+F12 (Windows/Linux) or Cmd+F12 (Mac) to see the JSON structure outline.
Frequently Asked Questions
What's the shortcut to format JSON in IntelliJ?
Ctrl+Alt+L on Windows/Linux or Cmd+Option+L on Mac. This works for any file type in IntelliJ, not just JSON. You can also use Ctrl+Shift+Alt+L / Cmd+Shift+Option+L to open the format dialog with additional options like "Optimize imports" and "Rearrange code".
How do I auto-format JSON on save in IntelliJ?
Go to Settings → Tools → Actions on Save and check "Reformat code". This applies to all file types. You can also enable "Optimize imports" and "Rearrange code" for additional cleanup on save. Now every time you press Ctrl+S / Cmd+S, IntelliJ formats your JSON automatically.
Why isn't my JSON formatting in IntelliJ?
Check that IntelliJ recognizes the file as JSON (look at the bottom right corner for file type). If it shows "Text" instead of "JSON", click it and select JSON. Also verify your JSON is syntactically valid - IntelliJ won't format invalid JSON. Look for red underlines indicating syntax errors and fix those first.
Can IntelliJ validate JSON as well as format it?
Yes, IntelliJ validates JSON syntax automatically and highlights errors with red underlines. Hover over errors to see messages. Press Alt+Enter / Option+Return on errors for quick fixes. You can also configure JSON Schema validation for structure validation beyond syntax. Go to Settings → Languages & Frameworks → Schemas and DTDs → JSON Schema Mappings.
How do I change the JSON indent size in IntelliJ?
Go to Settings → Editor → Code Style → JSON. Change the "Tab size" and "Indent" values. Set to 2 for compact formatting or 4 for more readable formatting. Click "Apply" then reformat your JSON with Ctrl+Alt+L / Cmd+Option+L. The new indentation applies immediately.
Can IntelliJ format JSON inside Java strings?
Yes. Select the JSON portion inside the string and press Ctrl+Alt+L / Cmd+Option+L. IntelliJ formats the JSON while preserving string escaping. This works for JSON embedded in any language - Java, JavaScript, Python, etc.
How do I format multiple JSON files at once in IntelliJ?
Select the folder containing JSON files in the Project view, right-click → Reformat Code, check "Include subdirectories" if needed, and click Run. IntelliJ formats all JSON files in the selected folder. This works for entire projects too.
Does IntelliJ support JSONC (JSON with comments)?
Yes, IntelliJ recognizes files like
tsconfig.jsonjsconfig.json.vscode/settings.jsonCan I format JSON without opening IntelliJ?
Use python -m json.tool input.json output.json from command line, or paste into jsonformatter.org. VS Code also has built-in formatting with Shift+Alt+F. But if you already use IntelliJ for development, it's the most convenient option.
What if I have a huge JSON file (100MB+)?
IntelliJ handles files up to 50MB smoothly. Above that, you might see slowdowns. For very large files, use Python's json.tool from command line or split the file first with a JSON splitter, format the chunks, then merge them back.
Related Tools
Need to work with JSON in other ways? These tools help:
- JSON Merger - Combine multiple JSON files into one
- JSON Splitter - Break large JSON files into smaller chunks
- JSON to Excel - Convert JSON to spreadsheet format
- JSON to Table - View JSON data in table format
- JSON Flattener - Flatten nested JSON structures
- How to Format JSON in Notepad++ - Alternative for lightweight editor users
Read More
All Articles
How to Format JSON in Notepad++: Quick Setup (2026)
Format JSON in Notepad++ with JSTool plugin. Complete guide covering plugin installation, keyboard shortcuts (Ctrl+Alt+M), validation, minification, troubleshooting, and advanced formatting techniques for clean, readable JSON.

JSON vs XML vs YAML: Which Data Format Should You Use? (2026)
Compare JSON vs XML vs YAML for APIs, config files, and data exchange. Includes syntax examples, performance benchmarks, readability tests, and use case recommendations for developers.

How to Add Image in JSON: 3 Easy Methods (2026)
Add images to JSON using URLs, base64 encoding, or file paths. Complete guide with code examples, size optimization tips, and best practices for each method in web and mobile apps.