17

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?

Justin Holmes
  • 171
  • 1
  • 1
  • 4
  • 2
    See http://stackoverflow.com/a/42118981/2631715 - instead of `[python]` you should be able to use `[json]`. – Gama11 Feb 08 '17 at 18:12
  • Thanks. Looks like JSON is subject to the same limitations described in http://stackoverflow.com/a/42118981/6139071 – Justin Holmes Feb 08 '17 at 21:47

2 Answers2

26

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

"[json]": {
  "editor.insertSpaces": true,
  "editor.tabSize": 2
}
zeljko_a
  • 3,725
  • 1
  • 22
  • 23
  • @JonathanPool I do not know why. I ti works for project settings.json in `.vscode/settings.json` and in global settings.json `~/.config/Code/User/settings.json` – zeljko_a May 16 '20 at 10:26
3

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/

Shaun Luttin
  • 133,272
  • 81
  • 405
  • 467