jsonvisual-studio-code

How do I control the formatting style of JSON in Visual Studio Code?


There is apparently built in support in VS Code to format JSON files. However, I do not see a way to customize the way the formatting is done (e.g. specifying line breaks before curly-braces, brackets, etc). I have also read some documentation related to this but it doesn't go into any detail. Is there a way to customize how the formatting works in Visual Studio Code for JSON files?


Solution

  • Default formatter of JSON have only few features, like changing tab size.

    Open Preferences with File > Preferences > Settings (Ctrl + ,) > User Settings (or Workspace Settings) tab > [JSON] "Edit in settings.json" link

    or

    Command Palette (Ctrl+Shift+P) > Preferences: Configure Language Specific Settings > JSON

    and add language specific settings.

    Refs: Creating User and Workspace Settings Language specific editor settings

    settings.json (sample)

    {
        "[json]": {
            // JSON specific settings goes here
            // "editor.tabSize": 4
        }
    }
    

    For further customization, use extensions found in market place.