Necronomicron
Necronomicron

Reputation: 1310

How can I format JSON document in Visual Studio Community 2019?

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

Answers (8)

stan
stan

Reputation: 239

MAC You can also Right-Click in the .json file and select "Format Document" or by shortcut

enter image description here

Windows VS 2022

enter image description here

Upvotes: 1

Spyros Aronis
Spyros Aronis

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

Faisal Imran
Faisal Imran

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

Visual Studio Components

Upvotes: 3

sscalvo
sscalvo

Reputation: 485

None of the above worked for me.

Instead

ALT + SHIFT + F

did the job!

Upvotes: 20

ATyrneno
ATyrneno

Reputation: 451

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

Before formatting:
before formatting

After formatting:
after formatting

Upvotes: 45

Pfalbaum
Pfalbaum

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

enter image description here

enter image description here

Then you can right click and choose Format Document.

enter image description here

Upvotes: 9

Neve
Neve

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

Pancho Guevara
Pancho Guevara

Reputation: 55

First CTRL+E then press key D.

Upvotes: 1

Related Questions