12

I tried Ctrl + K, Ctrl + D, but it only works for *.cs files. JSON file has no errors and it isn't big, but when I press Ctrl + K, Ctrl + D it says the command is unavailable. I tried some other combos that I've found in the internet but they don't work at all. I also don't have text editor options for JSON. Do I have to install something additionally for them to appear?

I have Visual Studio Community 2019 16.4.4 and Windows 10 x64.

Necronomicron
  • 1,150
  • 4
  • 24
  • 47

6 Answers6

23

If I understood your question, Ctrl+A, Ctrl+K+F works for me.

Before formatting:
before formatting

After formatting:
after formatting

ZygD
  • 22,092
  • 39
  • 79
  • 102
ATyrneno
  • 231
  • 2
  • 4
10

None of the above worked for me.

Instead

ALT + SHIFT + F

did the job!

sscalvo
  • 367
  • 4
  • 6
5

You could copy your code into a blank JSON file using the menus. I'm using Microsoft Visual Studio Community 2019 Version 16.8.5.

File -->New-->File-->Web-->JSON File

enter image description here

enter image description here

Then you can right click and choose Format Document.

enter image description here

Pfalbaum
  • 586
  • 3
  • 10
  • 26
  • 1
    if web modules are not installed there won't be json file option in menu. – Faisal Imran Jul 31 '21 at 09:36
  • 1
    Funny how they want you to install web stuff despite JSON having become the default configuration format for .NET Core / 5+ (desktop) projects too... sigh – Ray Feb 09 '22 at 16:07
1

First CTRL+E then press key D.

1

Ctrl+K, Ctrl+D is short key for formatting code in Visual Studio, but you need to have a web module (such as Node.js or ASP.NET) installed to format JSON.

Modify or Installing Components in Visual Studio

Visual Studio Components

Jeremy Caney
  • 7,102
  • 69
  • 48
  • 77
Faisal Imran
  • 269
  • 2
  • 15
-1

Ctrl+K, Ctrl+D works for me in VS2019 My file has the .json extension. I'm using Json.Net in my project as well.

If you're having problems, there are a few packages you could import to do it through code . See:

Neve
  • 367
  • 2
  • 9