Turn off auto formatting for json files in Visual Studio Code

Visual Studio-Code

Visual Studio-Code Problem Overview


I have checked my preference multiple times and ensured that all options related to format-on-save are set to false. And yet everytime I save a .json file I see my file getting formatted.

Visual Studio-Code Solutions


Solution 1 - Visual Studio-Code

EDIT: Uninstall the extension, there are many other far better maintained formatters out there (e.g. Beautify)

OK, check if you have installed this extension: "JS-CSS-HTML formatter".

Now if you have, press CTRL+SHIFT+P, type "Formatter" and you should see an option that says Formatter Config.

After selecting that option, a file named formatter.json opens and all you do is edit the property (named onSave) from having true to being false.

Restart vs code and voilĂ !! It stopped auto formatting. (yay!!!!)

Solution 2 - Visual Studio-Code

In Visual Studio Code, in order to stop autoformatting only for your json files add the following in settings.json file by opening User Settings - Preferences.

{   
    "[json]": {
        "editor.formatOnSave": false   
    }
}

Solution 3 - Visual Studio-Code

I am using the below version of VS Code

Version: 1.28.2 (user setup)
Commit: 7f3ce96ff4729c91352ae6def877e59c561f4850
Date: 2018-10-17T00:23:51.859Z
Electron: 2.0.9
Chrome: 61.0.3163.100
Node.js: 8.9.3
V8: 6.1.534.41
Architecture: x64

And turned it off with the following steps:

  1. CTRL+SHIFT+P
  2. Type Settings
  3. Select Preferences: Open User Settings

Now follow these image instructions:

Click Edit in settings.json Change shown user setting values

  1. Select Save All
  2. Restart VS Code

Solution 4 - Visual Studio-Code

In VS Code by default Save without Formatting is done by -

on Windows :
STEP 1 : Press CTRL + K then
STEP 2 : Press CTRL + Shift + S

on MAC :
STEP 1 : Press CMD + K then
STEP 2 : Press S

Solution 5 - Visual Studio-Code

look for Settings.json into "project/.vscode/settings.json"

{
    "editor.formatOnSave": false
}

Solution 6 - Visual Studio-Code

Worth to note

I like the json formatting that is enabled by default but only wanted to disable it when editing certain files (i.e. I didn't want some massive json files expanded after formatting).

To exclude those certain files from auto formatting, I made my changes and saved without formatting.

Go into your vs code keyboard shortcuts and see what Save without formatting is set to. In my case (mac user) it was CMD+K followed by S. If it's not set, create your own custom shortcut.

Solution 7 - Visual Studio-Code

go to file -> preferences -> settings -> search for Editor: Auto Indent and select none from drop down

also make this change in setting.json "editor.formatOnSave": false,

yah this will work...

Solution 8 - Visual Studio-Code

In addition to answers here, there are settings other than "editor.formatOnSave" that might be having a similar effect, which you might also want to disable - for example, I had enabled the following in my User Preferences (settings.json):

"editor.codeActionsOnSave": {
  "source.organizeImports": true
},

Solution 9 - Visual Studio-Code

Solutions All In One

solution 1

> config your settings.json file which in the .vscode folder, if not exists, just create one in the project root level directory.

enter image description here

1.1 disabled format on save for all files

{
    "eslint.autoFixOnSave": false,
    "editor.formatOnSave": false
}

1.2 only disabled format on save for .json file

{   
    "[json]": {
        "editor.formatOnSave": false   
    }
}

solution 2

> just using the VS Code GUI

To open your user and workspace settings, use the following VS Code menu command:

On Windows/Linux: File > Preferences > Settings On macOS: Code > Preferences > Settings

2.1 open workspace settings

> Command + Shift + P / Win + Shift + P

enter image description here

2.2 search the keyword (like, json) and set your config as you want

enter image description here

refs

https://code.visualstudio.com/docs/getstarted/settings

Solution 10 - Visual Studio-Code

my format was set to CMD k + s by default for VS Code to save without formatting. you could try that out

Solution 11 - Visual Studio-Code

enter image description here

Disable the checkbox to disable the code formattor.

Solution 12 - Visual Studio-Code

If it's for lonefy.vscode-js-css-html-formatter-0.2.3\out\src\formatter.json,

try applying:

{
    "onSave": false,
    "javascript": {...
...
}

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionuser3275211View Question on Stackoverflow
Solution 1 - Visual Studio-CodeKitanga NdayView Answer on Stackoverflow
Solution 2 - Visual Studio-CodelocropulentonView Answer on Stackoverflow
Solution 3 - Visual Studio-CodeArifMustafaView Answer on Stackoverflow
Solution 4 - Visual Studio-CodeAbhinav KinagiView Answer on Stackoverflow
Solution 5 - Visual Studio-CodeAbel ValdezView Answer on Stackoverflow
Solution 6 - Visual Studio-CodeGovind RaiView Answer on Stackoverflow
Solution 7 - Visual Studio-CodeSuraj MalgaveView Answer on Stackoverflow
Solution 8 - Visual Studio-CodeTim IlesView Answer on Stackoverflow
Solution 9 - Visual Studio-CodexgqfrmsView Answer on Stackoverflow
Solution 10 - Visual Studio-CodeZack117View Answer on Stackoverflow
Solution 11 - Visual Studio-CodeskytreeView Answer on Stackoverflow
Solution 12 - Visual Studio-CodeVkl125View Answer on Stackoverflow