How to Format JSON in Cursor
Quick answer: press Shift + Alt + F on Windows and Linux, or Shift + Option + F on macOS. Cursor is built on VS Code, so it uses the same JSON formatter and the same shortcut. You donโt need an extension or a prompt.
If the shortcut does nothing, check the language mode in the bottom-right corner of the status bar. It has to say JSON (or JSON with Comments). A file pasted into an untitled tab often starts as Plain Text.
Need a one-off format without opening an editor? Paste into the JSON Formatter. It validates as well, in your browser.
Everything from VS Code carries over
Cursor reads the same kind of settings.json as VS Code and runs the same JSON language features, so the setup from How to Format JSON in VS Code works unchanged:
- Command Palette:
Ctrl + Shift + P(Cmd + Shift + Pon Mac), then โFormat Documentโ. - Format on save: open Settings with
Ctrl + ,(Cmd + ,) and turn on Editor: Format On Save. - Prettier: install the Prettier extension from the Extensions view and set it as the default formatter. See Prettier vs VS Codeโs Built-in JSON Formatter for the trade-offs.
A minimal settings.json that formats both plain JSON and JSON-with-comments files (tsconfig.json, .vscode/settings.json) on save:
{
"[json]": {
"editor.defaultFormatter": "vscode.json-language-features",
"editor.formatOnSave": true
},
"[jsonc]": {
"editor.defaultFormatter": "vscode.json-language-features",
"editor.formatOnSave": true
}
}
Open it from the Command Palette with โPreferences: Open User Settings (JSON)โ. Cursorโs own AI settings live in a separate panel and donโt affect formatting.
The one shortcut thatโs different: Format Selection
In VS Code, Ctrl + K then Ctrl + F (Cmd + K, Cmd + F on Mac) formats only the selected text. In Cursor, Ctrl/Cmd + K opens the inline AI edit box, so that chord doesnโt reach the formatter.
Two ways around it:
- Select the text and run Format Selection from the Command Palette.
- Open Keyboard Shortcuts (
Ctrl + K,Ctrl + Sin VS Code; search โKeyboard Shortcutsโ in Cursorโs Command Palette), search for โFormat Selectionโ, and bind it to a key you like. Cursor may have already moved VS CodeโsCmd + Kchords to another prefix, and this is where youโd see it.
Should you ask the AI to format JSON?
For a short snippet, itโs harmless. For a real file, use the formatter:
- The formatter canโt change your data. It parses the JSON and prints it back. A language model rewrites the text, and in a long file it can drop an array item, round a number, โfixโ a value it thinks is a typo, or cut the output short.
- A model is slower and costs tokens. A 2,000-line config is a lot of output for something
Shift + Alt + Fdoes instantly. - A model hides errors. If the JSON is invalid, the formatter refuses and the editor underlines the problem. A model will usually just return something valid-looking, and you wonโt know what it changed.
Where the AI is useful: explaining a structure you donโt recognize, writing a JSON Schema for a file, or generating sample data. If it does edit a JSON file, compare the before and after with JSON Diff. It ignores key order, so any change it shows is a real change to the data.
Troubleshooting
โThere is no formatter for โjsonโ files installed.โ The built-in JSON language features extension is disabled. Open the Extensions view, show built-in extensions, and enable โJSON Language Featuresโ.
Format on save works in data.json but not in tsconfig.json. That file is JSON with Comments. Add the [jsonc] block shown above.
Nothing happens and thereโs no error. The JSON probably has a syntax error, such as a trailing comma or single quotes. The Problems panel (Ctrl + Shift + M) lists them. Debug Malformed JSON covers the usual suspects.
Prettier and the built-in formatter keep fighting. Set editor.defaultFormatter per language, as above, so only one of them runs.
Tags
Related Articles
How to Format JSON in VS Code (5 Easy Methods)
Format JSON in VS Code instantly with Shift+Alt+F. Learn 5 easy methods: shortcuts, auto-format, Prettier, and more. Free guide with real examples.
Prettier vs VS Code's Built-in JSON Formatter
Prettier or VS Code's built-in formatter for JSON? How each one lays out arrays, objects, package.json and comments, and how to pick one per project.
Format JSON in the Terminal: jq, Python, Node
Pretty-print JSON in the terminal with jq, python -m json.tool, Node or Prettier. Copy-paste commands for files, curl output, sorting keys and minifying.