Reputation: 1310
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.
Upvotes: 24
Views: 72578
Reputation: 239
MAC You can also Right-Click in the .json file and select "Format Document" or by shortcut
Windows VS 2022
Upvotes: 1
Reputation: 91
For anyone still wondering which shortcut is the "correct" one, you can type "Format Document" in the search bar on VS and you can check it from there.
It even points out the path to Edit -> Advanced -> Format Document
Microsoft Visual Studio Professional 2022
Upvotes: 1
Reputation: 289
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
Upvotes: 3
Reputation: 485
None of the above worked for me.
Instead
ALT + SHIFT + F
did the job!
Upvotes: 20
Reputation: 809
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
Then you can right click and choose Format Document.
Upvotes: 9
Reputation: 417
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:
Upvotes: 0