To format JSON in IntelliJ IDEA, place the cursor in a file the IDE recognizes as JSON and press Reformat Code (Ctrl+Alt+L on Windows/Linux, Cmd+Option+L on macOS); IntelliJ applies your project's JSON code-style rules for indentation, quote style, and line breaks without changing any of the data. JSON itself is a text format standardized as RFC 8259 (the same data-interchange spec published as ECMA-404) that only describes six value types — objects, arrays, strings, numbers, booleans, and null — so a formatter is free to rearrange whitespace without altering what the document means. That clean separation between meaning and layout is exactly why the JSON plugin bundled with IntelliJ handles .json files and JSON-shaped string literals inside Java, Kotlin, and JavaScript sources without any extra setup. If the status-bar language indicator reads Plain Text or Java rather than JSON, Reformat Code will still run, but JSON-specific rules — enforced quotes, trailing-comma cleanup, schema-aware indentation — will not apply. For minify, validation with line-and-column pinpointing, or formatting JSON you cannot open inside the IDE, a browser tool like JSON Formatter is a practical complement that runs entirely client-side.

how to format json in intellij
Format JSON in IntelliJ IDEA: Shortcuts and Browser

Format JSON Inside IntelliJ IDEA

IntelliJ IDEA's JSON support ships with the JavaScript and TypeScript plugin, which is bundled and enabled by default in every standard installation. That means a .json file in your project tree is treated as JSON the moment IntelliJ opens it — the status bar at the bottom of the editor window shows JSON as the file's language, and Reformat Code uses the JSON code-style rules configured under Settings → Editor → Code Style → JSON (or IntelliJ IDEA → Settings on macOS). The shortcut is consistent across JetBrains IDEs: Ctrl+Alt+L on Windows and Linux, Cmd+Option+L on macOS.

To reformat an entire file, place the cursor anywhere inside it and press the shortcut. To reformat only a block of text — for example, a JSON string pasted into a Java source file — select the text first, then press the shortcut; IntelliJ detects JSON syntax inside the selection and applies the matching rules. To preview which rules will be applied before committing to them, use Ctrl+Alt+Shift+L on Windows/Linux or Cmd+Shift+Option+L on macOS to open the Reformat Code dialog. There you can restrict the action to the current file, the selected scope, a directory, or the whole project, and toggle options like "Optimize imports" and "Rearrange code".

Scratch files are the cleanest place to format raw JSON without polluting a project. Press Ctrl+Shift+Alt+Insert on Windows/Linux or Cmd+Shift+Option+Insert on macOS, pick JSON from the language list, give it a name, and paste your JSON. Reformat Code works inside scratch files exactly as it does in a project file, and the scratch buffer is local to your IDE so the data never touches a remote server. For minification and for an error report that points to the exact line and column where the JSON breaks, IntelliJ's IDE alone is not the right tool — IntelliJ surfaces syntax errors in .json files as red squiggles with a tooltip, but it does not produce a single, copyable pinpoint and it has no built-in minify action. A browser-based formatter handles those gaps.

When IntelliJ's IDE Alone Is Not Enough

Three jobs come up often when working with JSON that IntelliJ's built-in tools cover only partially. Minifying — stripping every byte of whitespace to produce the smallest valid payload — is a one-click operation in a dedicated tool but a manual edit inside an IDE. Validation with a pinpoint error is more important than formatting in most debugging sessions, and IntelliJ's red-squiggle tooltip reports the offending token but not a clean "line X, column Y" coordinate you can paste into a chat or a bug report. Formatting JSON you cannot open in the IDE — for example, a payload from a curl response captured in a browser dev-tools tab, or a configuration blob served from a third-party API — is awkward inside an IDE because there is no file to attach.

A browser-based JSON Formatter complements the IDE workflow in those exact three cases: it beautifies with a chosen indent, minifies to one line, and validates against the standard with line-and-column error reporting — all running in the browser's native JavaScript engine so the data never leaves the page.

Format, Minify, or Validate JSON in Your Browser

  1. Open JSON Formatter in your browser.
  2. Paste or type your JSON into the input box on the left.
  3. Pick an indent style — 2 spaces, 4 spaces, or Tab — to match your project's code-style, then click Format to beautify the document with newlines and matching indentation.
  4. Click Minify instead when you need the smallest valid payload for network transfer, URL embedding, or storage in a database field.
  5. If the JSON is invalid, read the line and column shown in the error message and jump to that position in your input to fix it; if the JSON parses, click Copy to copy the formatted or minified result to your clipboard.

Because both operations round-trip through the browser's native JSON.parse and JSON.stringify, the output is canonical, standards-compliant JSON — the structure and values are preserved exactly, only the whitespace changes. A paste-then-format session for a typical API response takes about the same time as opening a scratch file and pressing Ctrl+Alt+L in the IDE, with the bonus of a clean error coordinate when the parse fails.

What the Validator Catches — and Why

The most common reasons a "looks fine" JSON document refuses to parse are syntax differences between JavaScript object literals and the JSON spec. The browser formatter surfaces these as a clear error message plus a line and column, which is faster than squinting at a red squiggle in the IDE.

ConstructValid in JSON?Valid in JavaScript?What the validator reports
Double-quoted keys and string valuesYesYesNo error
Single-quoted keys or string valuesNoYesUnexpected token or invalid string
Trailing comma after the last array item or object propertyNoYesUnexpected token (usually } or ])
Unquoted object keys (e.g. {name: "x"})NoYesUnexpected token
Comments (// or /* */)NoYesUnexpected token or invalid character
undefined, NaN, InfinityNoYesUnexpected token
Integer larger than 9,007,199,254,740,991Round-trips with precision lossRound-trips with precision lossNo error, but value changes — keep as a string

The last row is the subtle one. JSON numbers are parsed by the browser as IEEE-754 doubles, the same numeric type JavaScript uses, so any integer beyond Number.MAX_SAFE_INTEGER (2^53 − 1, or 9,007,199,254,740,991) loses precision in both the validator and the IDE: a value like 12345678901234567890 comes back as 12345678901234567000. If your JSON carries Twitter/X snowflake IDs, 64-bit database keys, or any other identifier that needs exact integer fidelity, keep those values as quoted strings and let the consuming code parse them with a big-integer library.

Beautify or Minify — Pick the Right Operation

Beautifying (pretty-printing) is what you reach for during debugging. A 5,000-character single-line response becomes a browsable tree the moment you add newlines and indentation, and IntelliJ's Reformat Code does exactly that for files inside the IDE. Minifying is the opposite: it strips every space and newline to produce the smallest valid payload, which is what you want for network transfer, embedding JSON in a URL query string, or storing the document in a database field where every byte counts. On large API responses, stripping indentation can shrink the payload substantially before compression — exact savings depend on nesting depth and transport, so test with a real sample when the size matters. The browser formatter handles both with a single click, so the usual workflow is to beautify first (to read and fix), then minify the corrected version (to ship).

Browser-Side Processing and the Standards It Follows

Everything in the browser formatter happens client-side. Parsing and serialization use the JavaScript engine's native JSON.parse and JSON.stringify, which are compliant with RFC 8259 — The JavaScript Object Notation (JSON) Data Interchange Format and the equivalent ECMA-404 standard. Your JSON never leaves the page, so it is safe to format API responses, access tokens, or private configuration blobs without uploading them to a backend — a real difference from tools that POST your data to a remote endpoint. The same property holds inside IntelliJ IDEA for scratch files and local projects: neither the IDE nor the browser tool sends your data anywhere for processing.

Typical workflows combine both tools: paste a curl response from a browser dev-tools tab into the browser formatter to beautify and validate, copy the clean version into an IntelliJ scratch file for editing, and use Reformat Code on the scratch file before pasting the final shape back into a real project source. The IDE handles project-style formatting and live error squiggles; the browser handles minify, validation with exact line-and-column coordinates, and any JSON you cannot load into the IDE at all.

If you're weighing options, How to Compress a JSON File Safely in Your Browser covers this in detail.

If you're weighing options, Create JSON Schema in Python From a JSON Sample covers this in detail.