DEV Community 👩‍💻👨‍💻

Cover image for Create a class from a JSON in Visual Studio 2022
Emanuele Bartolesi
Emanuele Bartolesi

Posted on

Create a class from a JSON in Visual Studio 2022

It happens very often, during the development, to have some objects that are returned by some API and of which we want to create a class.
If the object are big with a lot of subnodes, it should be a long activity and, first of all, very annoying.

The Visual Studio team improved this feature in the last version of the IDE.

How to use this feature

Create an empty class or just a file with the namespace declaration.

an empty file

Then you can copy your JSON into the clipboard and in Visual Studio go to Edit -> Paste Special -> Paste JSON as Classes

Paste special menu

This feature is very fast right now. With the previous version of Visual Studio, sometimes, you had issues to create a class from a big JSON file.

Keyboard Shortcut

By default this command is not associated to any keyboard shortcut.
In my environment I configured that from the menu Tools -> Options.

Paste as Class keyboard shortcut

I choosen Ctrl+V, Ctrl+J but you can choose your favourite shortcut for this special action.

Top comments (0)

Take a look at this:

Settings

Go to your customization settings to nudge your home feed to show content more relevant to your developer experience level. 🛠