Free & private — your files never leave your device.Compress a photo to 100 KB →
Popular
Back to Blog

How to Format JSON in IntelliJ: Quick Shortcuts & Tips

If you build APIs, debug microservices, or write automation scripts, you know the fatigue of staring at a massive, unformatted wall of data. Raw API responses spanning a single, endless line slow down troubleshooting. If you are wondering how to format json in intellij, the IDE has built-in code formatting tools that instantly turn messy payloads into a clean structure.

Beyond the default shortcut, you need to manage custom indentation, handle large payloads without lagging your workspace, and fix stubborn syntax errors. Let us walk through everything required to master JSON formatting inside IntelliJ IDEA.

Quick Answer: The Default IntelliJ JSON Format Shortcut

To clean up your current file immediately, use the built-in keyboard shortcut to trigger the code style engine.

  • Windows and Linux shortcut: Press Ctrl + Alt + L for standard code reformatting.
  • macOS shortcut: Press Cmd + Option + L to tidy up the active JSON file.

When you trigger this command, IntelliJ fixes bracket placement, adjusts indentation, cleans up spacing around colons and commas, and aligns your data structures. To format a specific chunk of text, highlight the lines with your mouse before pressing the shortcut, and IntelliJ will restrict changes to your selection.

How to Configure Custom JSON Indentation and Code Style in IntelliJ

Default four-space indentation might not match your team style guide. Many teams prefer a tighter two-space indent or require specific wrapping rules for arrays and objects. You can adjust these rules globally or per project.

  1. Navigate to Settings (or Preferences on macOS) via the top menu.
  2. Expand the Editor section, click on Code Style, and select JSON.
  3. Under the Tabs and Indents tab, change the tab size and indent values to match your team guidelines, such as setting spaces to 2 instead of 4.
  4. Explore the other tabs to configure wrapping, brace placement, and single-line object rules.
  5. Click apply and save.

If your team works across different IDEs, enforce these rules repository-wide by adding an .editorconfig file to your project root. IntelliJ reads these configuration files automatically, ensuring everyone formatting JSON files in the repository ends up with identical spacing and line breaks.

Formatting Minified or Single-Line JSON Payloads

A common headache involves copying a massive single-line JSON payload from an application log or browser network tab, only to paste it into an empty file as an unreadable block. Manually adding line breaks to a large log file wastes time.

To handle this smoothly, avoid pasting directly into a heavy project file if you just want to inspect data. Instead, use IntelliJ scratch files. Press Ctrl + Shift + Alt + Insert (or the macOS equivalent) and choose JSON as the language. This opens a lightweight scratchpad sandbox where you can paste minified payloads without cluttering your source code repository.

Once you paste the single-line payload into your scratch file, hit your reformatting shortcut. IntelliJ parses the structure, adds proper indentation, and provides full structural navigation, allowing you to collapse and expand parent objects effortlessly.

An honest limitation of working inside a heavy IDE: if your log file spans hundreds of megabytes or contains millions of lines, IntelliJ might freeze or run out of memory when building the syntax tree. For massive data dumps, a dedicated utility like a JSON Formatter & Validator handles the heavy lifting instantly without bogging down your machine’s RAM.

Troubleshooting Common JSON Parsing Errors in IntelliJ

Sometimes you hit your formatting shortcut, but nothing happens, or IntelliJ throws a red squiggly error line across your screen. JSON is strict about syntax, and a single missed character breaks the parser.

IntelliJ includes a built-in validator that highlights issues like unquoted keys, trailing commas, or missing closing brackets. Here is how to tackle the most common culprits:

  • Trailing commas: JavaScript allows trailing commas in arrays and objects, but standard JSON does not. If IntelliJ highlights a comma at the end of your last key-value pair, delete it.
  • Unquoted keys: Property names must be wrapped in double quotes. Data exported directly from a JavaScript object literal requires quotes added around keys.
  • Single quotes: JSON only accepts double quotes for strings. Replacing single quotes with double quotes is essential for valid parsing.

If you are dealing with malformed configuration logs that contain a mix of comments and trailing commas, use IntelliJ structural search and replace to strip out invalid syntax before running your formatting shortcut. Cleaning up these syntax errors allows the IDE to recognize the structural tree and apply proper indentation.

Alternative: Format JSON Instantly in Your Browser Without Opening Heavy Projects

There are times when you are away from your main development workstation or need to check a quick payload without spinning up a heavy IDE instance. Opening a massive project just to format a configuration snippet is overkill.

When you need a lightweight way to validate, format, or convert data on the fly, browser-based utilities save time. You can paste raw payloads into the JSON Formatter & Validator to clean up messy structures, inspect errors, and minify data for transport without installing plugins.

Furthermore, if you need to hand off API data to a non-technical team member or pull analytical information into a spreadsheet, you can transition your data structures smoothly. Instead of writing a custom script, use the JSON to CSV Converter to transform structured arrays into spreadsheet-ready formats in seconds.

FAQ

What is the shortcut to format JSON in IntelliJ on Windows?

The standard keyboard shortcut to reformat code, including JSON files, on Windows and Linux is Ctrl + Alt + L. This triggers the built-in code style engine to fix indentation, spacing, and line breaks automatically.

How do I fix JSON syntax errors automatically in IntelliJ IDEA?

While IntelliJ highlights syntax errors with red underlines, it cannot always fix structural mistakes like unquoted keys or trailing commas automatically. You must manually correct those specific violations before the code style formatter can organize your data.

Can IntelliJ format JSON without opening a full project?

IntelliJ requires an open project or workspace to run its editor features. If you need a fast formatting check outside your coding environment, using a web-based tool is much quicker than launching the full IDE.

How do I change the default 4-space JSON indentation to 2 spaces in IntelliJ?

Go to Settings or Preferences, navigate to Editor, Code Style, and then JSON. Under the Tabs and Indents tab, adjust the indent and tab size values from 4 to 2, then save your changes.

Mastering JSON formatting in IntelliJ IDEA keeps your codebase clean, saves you from visual fatigue, and speeds up your daily debugging workflow. Whether you rely on quick keyboard shortcuts, project-level code style rules, or lightweight browser utilities for massive payloads, keeping your data structured properly makes development much smoother.