DEV Community

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

Posted on

3

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.

Hostinger image

Get n8n VPS hosting 3x cheaper than a cloud solution

Get fast, easy, secure n8n VPS hosting from $4.99/mo at Hostinger. Automate any workflow using a pre-installed n8n application and no-code customization.

Start now

Top comments (0)

Heroku

Build apps, not infrastructure.

Dealing with servers, hardware, and infrastructure can take up your valuable time. Discover the benefits of Heroku, the PaaS of choice for developers since 2007.

Visit Site

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay