11 min read read
By Imad Uddin

How to Format JSON in IntelliJ: Shortcuts & Auto-Format Setup (2026)

How to Format JSON in IntelliJ: Shortcuts & Auto-Format Setup (2026)

IntelliJ has built-in JSON formatting - no plugins needed. Press Ctrl+Alt+L (Windows/Linux) or Cmd+Option+L (Mac) on any JSON file to format it instantly.

Method 1: Keyboard Shortcut (Fastest)

  1. Open your JSON file in IntelliJ
  2. Press Ctrl+Alt+L (Windows/Linux) or Cmd+Option+L (Mac)
  3. Done - IntelliJ reformats with consistent indentation

Before formatting:

{"name":"John","age":30,"skills":["Java","Python"],"active":true}

After Ctrl+Alt+L:

{
  "name": "John",
  "age": 30,
  "skills": [
    "Java",
    "Python"
  ],
  "active": true
}

Method 2: Right-Click Menu

  1. Right-click anywhere in the JSON file
  2. Select "Reformat Code"

This does exactly the same thing as the keyboard shortcut but through the context menu.

Method 3: Configure Formatting Rules

  1. Go to Settings/PreferencesEditorCode StyleJSON
  2. Adjust indent size, spacing around colons, max line length
  3. 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
  • Wrap arrays: Control when arrays wrap to new lines

Formatting on Save (Auto-Format)

  1. SettingsToolsActions on Save
  2. Check "Reformat code"
  3. Now JSON formats automatically every time you save

This is the most convenient option. Your JSON stays formatted without thinking about it.

JSON Validation and Error Detection

IntelliJ validates JSON syntax in real-time. Common errors it catches:

Trailing commas (invalid JSON):

{
  "name": "John",
  "age": 30,
}

IntelliJ highlights the trailing comma and offers a quick fix.

Single quotes (invalid JSON):

{
  'name': 'John'
}

IntelliJ shows an error and can convert to double quotes with Alt+Enter.

Missing commas:

{
  "name": "John"
  "age": 30
}

IntelliJ indicates where commas are missing.

Advanced JSON Features

JSON Schema validation: Go to SettingsLanguages & FrameworksSchemas and DTDsJSON Schema Mappings to validate against schemas.

JSON Path testing: IntelliJ supports JSON Path expressions for extracting data from JSON structures.

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 to open the format dialog with additional options.

How do I auto-format JSON on save in IntelliJ?

Go to SettingsToolsActions 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.

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", right-click the file and choose "Associate with File Type" → JSON. Also verify your JSON is syntactically valid.

Can IntelliJ validate JSON as well as format it?

Yes, IntelliJ validates JSON syntax automatically and highlights errors in red. You can also configure JSON Schema validation for structure validation beyond syntax. Use Alt+Enter on highlighted errors for quick fixes and suggestions.

How do I change the JSON indent size in IntelliJ?

Go to SettingsEditorCode StyleJSON. 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.

Read More

All Articles