Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Configure vscode json formatting spaces

I would like to configure the vscode to format my JSON objects with 2 spaces of indent, not 4 as it does by default. How can I do this?

like image 899
Justin Holmes Avatar asked Feb 08 '17 17:02

Justin Holmes


People also ask

How do you set spacing in VS Code?

Type “Indentation” into the search field then head to the “Editor: Tab Size” section. Replace the default space number with your preferred one: Your setting will be applied and reflected immediately. If this doesn't happen (it's a little lag sometimes), just reload or restart your VS Code.

How do I beautify JSON in VS Code?

Formatting# You can format your JSON document using Ctrl+Shift+I or Format Document from the context menu.

How do I change JSON settings in VS Code?

json file. You can open the settings. json file with the Preferences: Open Settings (JSON) command in the Command Palette (Ctrl+Shift+P). Once the file is open in an editor, delete everything between the two curly braces {} , save the file, and VS Code will go back to using the default values.


2 Answers

Paste in this lines in settings.json in VSCode, and you're all set:

"[json]": {
  "editor.insertSpaces": true,
  "editor.tabSize": 2
}
like image 69
zeljko_a Avatar answered Sep 20 '22 16:09

zeljko_a


Install the editor config plugin.

ext install EditorConfig

Add an .editorconfig file to your project root with the following:

[*.json]
indent_style = space
indent_size = 2

See also:

https://github.com/editorconfig/editorconfig-vscode

http://editorconfig.org/

like image 24
Shaun Luttin Avatar answered Sep 20 '22 16:09

Shaun Luttin