Free · Fast · Privacy-first

Format JSON in VS Code, and What to Do When It Fails

VS Code has a built-in JSON formatter that works reliably when the JSON is syntactically valid.

Diagnoses errors VS Code will not format

🔒

Matches VS Code 2-space default indentation

Works in any browser without extensions

Instant feedback on syntax problems

Cost
Free forever
Sign-up
Not required
Processing
In your browser
Privacy
Files stay local
FreeNo signupWhite-label

Add this JSON Formatter to your website

Drop the JSON Formatter into any page — blog post, product docs, intranet, school portal — with a single line of HTML. Your visitors get the full tool, processed entirely in their browser. No backend, no uploads, no signup.

  • Files stay 100% in the visitor's browser
  • Responsive — adapts to any container width
  • Free forever, no API key needed

Embed code

<iframe
  src="https://www.fixtools.io/json/json-formatter?embed=1"
  width="100%"
  height="780"
  frameborder="0"
  style="border:0;border-radius:16px;max-width:900px;"
  title="JSON Formatter by FixTools"
  loading="lazy"
  allow="clipboard-write"
></iframe>

Attribution-friendly: a small "Powered by FixTools" link appears in the embed footer.

Why VS Code Refuses to Format Invalid JSON

VS Code ships with a built-in JSON language server that provides formatting, validation, autocompletion, and hover documentation for JSON files. The formatter is triggered by the Format Document command (Shift+Alt+F on Windows and Linux, Shift+Option+F on macOS) or automatically when the editor.formatOnSave setting is enabled. However, the VS Code JSON formatter requires the file to be syntactically valid before it will produce output. If the file contains a syntax error, the formatter returns early and leaves the document unchanged. The editor may show a red squiggle at or near the error position, but the associated error message is sometimes as unhelpful as "Expected comma" without indicating which expected comma at which location.

The VS Code JSON language server is built on the vscode-json-languageservice npm package, which uses the jsonc-parser library internally. This parser accepts JSONC (JSON with Comments), which is why files with a .jsonc extension and VS Code's own settings.json and extensions.json can contain // single-line and /* */ block comments. Pure .json files are validated more strictly against the RFC 8259 standard. When you run Format Document and nothing happens, the most likely cause is a syntax error that the language server has detected but has not surfaced prominently in the editor UI. The Problems panel accessible via View > Problems lists all detected errors with file name, line number, and a text description, and is more informative than the editor squiggle alone.

Pasting the JSON into FixTools is the fastest way to identify and fix the exact syntax error before returning to VS Code. FixTools uses the browser's native JSON.parse(), which is RFC 8259-compliant and reports the exact character position of the first error it encounters. The error message from the browser's JSON parser is often more precise than the one VS Code surfaces in its Problems panel, because it reports the character the parser actually encountered rather than the character it was waiting for. Once you fix the error and copy the formatted output back into VS Code, the file is valid and VS Code's own formatter and language server features will work normally for all subsequent edits.

VS Code users hit a recurring confusion around JSON5 and JSONC. The editor recognises three flavors: strict .json files which forbid comments and trailing commas, .jsonc files which allow both, and JSON5 files which require the vscode-json5 extension to handle the wider grammar including unquoted keys and single-quoted strings. Default settings.json, keybindings.json, and tsconfig.json are treated as JSONC by file association rules in VS Code's package.json. If you copy a tsconfig.json into a tool that does not understand JSONC, including FixTools or a build script that uses strict JSON.parse, the comments will trigger errors. Strip them with a JSONC preprocessor such as the jsonc-parser npm package, or rename the file to .jsonc and accept that downstream tooling needs JSONC support.

VS Code's built-in JSON formatter and Prettier behave differently enough on edge cases to be worth distinguishing. The built-in formatter uses your editor.tabSize and editor.insertSpaces settings, applies them globally to all JSON files in the workspace, and runs synchronously on Format Document. Prettier reads its own .prettierrc and ignores VS Code editor settings, runs asynchronously through the VS Code Prettier extension or via a pre-commit hook, and handles a broader range of file types with one shared configuration. For team consistency, Prettier wins because the .prettierrc lives in the repository and applies identically across every developer's machine regardless of their individual editor preferences. For a single-developer hobby project, the built-in formatter is sufficient and avoids the dependency on a Node-based formatter binary.

How to use this tool

💡

Paste the JSON from your VS Code file here to identify syntax errors, fix them, and get clean formatted output ready to paste back.

How It Works

Step-by-step guide to format json in vs code, and what to do when it fails:

  1. 1

    Copy from VS Code

    Select all content in your VS Code JSON file using Ctrl+A (Windows/Linux) or Cmd+A (macOS) and copy it to your clipboard. Include the full file content so the validator can check the complete structure including the opening and closing brackets.

  2. 2

    Paste into FixTools

    Paste the JSON into the FixTools JSON Formatter input area. The editor accepts the full file content regardless of its current indentation or whether it contains syntax errors.

  3. 3

    Review the error

    If the JSON is invalid, FixTools highlights the error position in the input and displays a message explaining what is wrong, including the line and column number where the parser detected the problem.

  4. 4

    Fix and format

    Correct the syntax error in the input field, then click Format. If the fix was correct, the formatted output appears. If there are additional errors, the next one is reported for you to address.

  5. 5

    Paste back into VS Code

    Copy the formatted output and paste it into VS Code, replacing the original file content. The file is now valid and VS Code's formatter and IntelliSense will work on it normally.

Real-world examples

Common situations where this approach makes a real difference:

A developer edits a tsconfig.json file manually, accidentally leaving a trailing comma after the last compiler option key. VS Code shows a red squiggle but Format Document does nothing and the Problems panel message is not specific enough to locate the comma. Pasting into FixTools flags the exact line and column of the trailing comma, allowing the developer to remove it and paste the corrected file back in under 30 seconds.

Trailing commas are the most common reason VS Code refuses to format JSON config files like tsconfig.json and package.json.

A DevOps engineer copies a JSON configuration snippet from a Slack message into a VS Code Kubernetes manifest. The snippet used single-quoted string values instead of double-quoted strings because the sender copied it from a Python dictionary literal. VS Code underlines the first single-quoted value but the error description is unclear. FixTools explains that all strings must be double-quoted per RFC 8259 and identifies every single-quoted string in the document.

Single-quoted strings from Python or JavaScript source code frequently appear in JSON files pasted from chat or documentation.

A developer has a large package.json with a missing comma between two dependency entries that were added in two separate editing sessions. VS Code's squiggle appears several lines below the actual missing comma because the parser reports the position where it first detects a problem, not where the comma should have been. FixTools gives the same error position but with the surrounding context visible in the formatted output, making the correct insertion point clear.

JSON parser error positions often point to the next unexpected token rather than the location of the actual missing character.

A developer new to the team is not yet familiar with VS Code keyboard shortcuts and does not know how to trigger Format Document or where to find the Problems panel. They use FixTools as an accessible alternative: paste the file, click Format, copy the result. This workflow produces correctly formatted JSON without requiring knowledge of VS Code settings, extension configuration, or the specific keyboard shortcut for the format command.

Browser-based formatters are accessible to developers regardless of their familiarity with VS Code's interface.

Pro tips

Get better results with these expert suggestions:

1

Enable formatOnSave in VS Code for JSON

Add "editor.formatOnSave": true to your VS Code user or workspace settings.json. To apply this setting only to JSON files, use the language-scoped override: "[json]": { "editor.formatOnSave": true }. This automatically formats your JSON file on every save as long as it is valid. Combine it with Prettier (esbenp.prettier-vscode extension) and a .prettierrc file to ensure consistent indentation across all team members.

2

Use the Problems panel for JSON errors

When VS Code refuses to format a JSON file, open the Problems panel with Ctrl+Shift+M (Windows/Linux) or Cmd+Shift+M (macOS). The JSON language server lists all detected syntax errors with the file path, line number, column, and a text description. This panel shows all errors simultaneously rather than one at a time, which is faster for fixing files with multiple issues.

3

JSONC vs JSON in VS Code

VS Code treats files with the .jsonc extension as JSON with Comments, allowing // and /* */ comments. If you need to add explanatory comments to a JSON config file, rename it to .jsonc so VS Code handles it with the more permissive JSONC parser. The tsconfig.json file is already treated as JSONC by VS Code, which is why it accepts comments despite having a .json extension.

4

Install Prettier for consistent team JSON formatting

The Prettier VS Code extension (esbenp.prettier-vscode) formats JSON files using a shared .prettierrc configuration committed to the repository. This ensures every team member produces the same indentation, quote style, and line endings regardless of their individual VS Code settings. Run Prettier as a pre-commit hook and in your CI pipeline to enforce the standard before code is merged.

FAQ

Frequently asked questions

VS Code's JSON formatter requires the file to be syntactically valid before it will produce output. If there is a syntax error anywhere in the file, the formatter returns early and the document is unchanged. Open View > Problems (Ctrl+Shift+M) to see the full list of detected errors. The most common causes include trailing commas after the last key-value pair or array item, single-quoted strings, unquoted key names, a missing comma between two adjacent key-value pairs, or mismatched braces. Fix the syntax error and run Format Document again.
On Windows and Linux the shortcut is Shift+Alt+F. On macOS it is Shift+Option+F. Alternatively, right-click anywhere in the editor and choose Format Document from the context menu. You can also open the Command Palette with Ctrl+Shift+P (Windows/Linux) or Cmd+Shift+P (macOS), type "Format Document", and press Enter. If no default formatter is configured for JSON files, VS Code prompts you to select one from the available options.
Open VS Code Settings and add "editor.formatOnSave": true. For JSON files specifically, use a language-scoped setting: add "[json]": { "editor.formatOnSave": true } to apply it only to JSON files. This requires a formatter to be available. The built-in VS Code JSON formatter works without any extension. For team-consistent output, install the Prettier extension (esbenp.prettier-vscode) and set it as the default JSON formatter.
VS Code's built-in JSON formatter is part of the vscode-json-languageservice and uses your editor.tabSize setting to determine indentation. Prettier is a separate opinionated formatter that uses its own configuration file (.prettierrc) and ignores individual editor settings. For team projects, Prettier is preferred because it produces identical output for all developers regardless of their personal VS Code configuration. Prettier also covers many file types beyond JSON, so one configuration file handles your entire project.
Yes. VS Code supports JSONC natively. Files with a .jsonc extension are handled with the JSONC parser, which allows // single-line comments and /* */ block comments. VS Code's own settings.json, extensions.json, and launch.json files are treated as JSONC, which is why they accept comments. Standard .json files with comments fail RFC 8259 validation and VS Code will show an error. Rename the file to .jsonc if you need comments in the file.
Hover your cursor directly over the squiggle to see the error tooltip. For more detail, open the Problems panel via View > Problems. The JSON language server may place the squiggle at a position several tokens after the actual missing character because parsers report where they first encounter an unexpected token, not necessarily where the missing token should have been. Use FixTools with the same JSON to get the browser's JSON.parse() error message as a second diagnostic, which sometimes points more precisely at the root cause.
Yes, for one-off formatting tasks. Copy your JSON from VS Code, paste it into FixTools, click Format, copy the output, and paste it back. For ongoing editing in VS Code, the built-in formatter or Prettier is more convenient because it reformats the open file in place without switching applications. FixTools is most useful when the file has syntax errors preventing VS Code from formatting, when you are on a machine without VS Code installed, or when you want a second opinion on what a syntax error actually is.
Yes. VS Code uses your editor.tabSize setting (default is 4) when formatting JSON with the built-in formatter. To use 2-space indentation for JSON specifically, add "[json]": { "editor.tabSize": 2 } to your settings.json. This overrides the global tab size for JSON files only. If you use Prettier, set "tabWidth": 2 in your .prettierrc file and Prettier uses that value regardless of the VS Code editor.tabSize setting.
The vscode-json-languageservice has an internal size cap, around 5MB by default, beyond which the language server stops providing formatting and IntelliSense to keep the editor responsive. Files above the cap show no red squiggle, no formatter action, and no auto-completion, which looks identical to the file being formatted already. Check the Output panel with View > Output and select JSON Language Server in the dropdown to see whether the server skipped the file. For very large config dumps, format outside VS Code with jq, save the result, and reopen. Alternatively, run jq . file.json | code - to pipe formatted output into a new VS Code buffer that bypasses the on-disk size check entirely.
VS Code settings.json frequently contains API tokens for extensions such as GitHub, GitLab, or cloud providers. FixTools processes content client-side and never transmits it, but the safer pattern is to redact secrets before pasting. Replace each token value with a placeholder like "REDACTED_API_KEY" before copying, especially when troubleshooting a syntax error you plan to share in a bug report or chat. After confirming the formatted structure, restore the real values in your local file. For Cursor and other VS Code forks that sync settings to a remote service, this hygiene step prevents the redacted values from leaking into a synced settings store along with your fix.

Ready to get started?

Open the full JSON Formatter — free, no account needed, works on any device.

Open JSON Formatter →

Free · No account needed · Works on any device