In Visual Studio Code (under Windows), my present Json files are displayed as the following :
I would them to be formatted as displayed below :
In Visual Studio Code (under Windows), my present Json files are displayed as the following :
I would them to be formatted as displayed below :
In 2022 it's Ctrl+Shift+I as stated on the Visual Studio Code website.
Press Ctrl-Shift-p to format the documents. I don't know if this shortcut works on Windows, but it does on Linux.
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.
Install a code formatting extension then save the file.