Reputation: 1040
In Visual Studio Code (under Windows), my present Json files are displayed as the following :
I would them to be formatted as displayed below :
Upvotes: 19
Views: 41255
Reputation: 172
If you need to setup the formatting to be consistent on every project you work, you can create a .vscode directory on the project root, create a settings.json file inside the .vscode directory.
To format JSON files you can add the following json to the settings.json file.
{
"[json]": {
"editor.defaultFormatter": "vscode.json-language-features",
"editor.tabSize": 2,
"editor.formatOnSave": true,
"editor.insertSpaces": true,
"editor.detectIndentation": false,
}
}
This would format the file when you save it. You can set tabSize to whatever size you prefer. insertSpace would add spaces instead of tabs when you use tabs. detectIndentation would ignore the current file indentation method and will stick to your specific settings.
Upvotes: 1
Reputation: 2046
For MacOS, if shortcuts didn't worked there might be conflicts between the formatters plugins. Try
select the code -> right click -> choose format selection
Upvotes: 0
Reputation: 215
RIGHT CLICK and Select Source Action then JSON file will be converted to JSON format
Upvotes: 4
Reputation: 371
On your Mac, you can do so by pressing command+shift+p and then type or select "JSON: Sort Document"
Upvotes: 1
Reputation: 701
In 2022 it's Ctrl+Shift+I
as stated on the Visual Studio Code website.
Upvotes: 7
Reputation: 9
Install Prettier using the extensions, and then right click, select format document with and pick Prettier.
Upvotes: 0
Reputation: 356
Press Ctrl-Shift-p to format the documents. I don't know if this shortcut works on Windows, but it does on Linux.
Upvotes: 2