Configure vscode json formatting spaces
Asked Answered
M

2

19

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?

Mukul answered 8/2, 2017 at 17:55 Comment(2)
See https://mcmap.net/q/202506/-how-to-set-python-language-specific-tab-spacing-in-visual-studio-code - instead of [python] you should be able to use [json].Telangiectasis
Thanks. Looks like JSON is subject to the same limitations described in https://mcmap.net/q/202506/-how-to-set-python-language-specific-tab-spacing-in-visual-studio-codeMukul
T
28

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

"[json]": {
  "editor.insertSpaces": true,
  "editor.tabSize": 2
}
Theotheobald answered 22/2, 2018 at 5:54 Comment(1)
@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.jsonTheotheobald
S
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/

Silverware answered 9/2, 2017 at 3:7 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.