Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio JSON indenting

Visual Studio seems to ignore my indenting setting for JSON files. It is indenting 4 spaces, instead of my setting of 2 spaces: indenting settings

When I format the document it looks like this:

formatted document

I am using:

Microsoft Visual Studio Professional 2022 (64-bit)
Version 17.5.1

like image 277
Nicola Ambrosetti Avatar asked Oct 27 '25 04:10

Nicola Ambrosetti


2 Answers

It turned out that the project had an .editorconfig file in the root folder with

[*]
indent_style = space
indent_size = 4

This was overriding all the indenting options since it was "Following the project coding conventions" enter image description here

UX tip to Microsoft: make it somehow visible in the Options window that some settings are overridden.

like image 85
Nicola Ambrosetti Avatar answered Oct 30 '25 01:10

Nicola Ambrosetti


If you leave indenting set to Smart or Block, it will match the rest of the file (or block) and ignore your choice.

To reproduce this I followed these steps:

  • Set Indenting to "Smart" and Tab size/Indent Size to 8.
  • Create a file and add "sss":"x", and "js":"e" with size 8.
  • Change indenting to "None" and Tab/Indent to 3.
  • add "," to the "js" line and hit return.
  • It then uses size 3 as shown in the photo: example json
like image 41
James Risner Avatar answered Oct 30 '25 02:10

James Risner