Visual Studio 2022: An Improved Paste JSON as Classes

Visual Studio 2022 offers so many new features that we easily overlook how existing features have been improved. In today’s post, I like to point out how “Paste JSON as Classes” got better and better. Pasting XML or JSON as classes exists since Visual Studio 2017. However, in Visual Studio 2022 you can work with complex object graphs that earlier Visual Studios could not handle.

Before you can use this feature, you need a place where you can paste your classes. An empty file or a namespace declaration is enough:

Then you can copy your JSON into the clipboard and go in Visual Studio to
Edit / Paste Special / Paste JSON AS Classes:

Go to Edit / Paste Special / Paste JSON AS Classes

Visual Studio 2022 nearly instantly pastes the code for the classes into your file:

To see how much this feature improved I used the return data of Twitter’s Bookmarks feature. Visual Studio 2017 crashed, while Visual Studio 2022 created the enormous object graph without any problems or delays. And this object graph is huge (206 classes):

The Bookmarks feature uses an enormous number of classes.

If you can throw this object graph at Visual Studio 2022, it will work with everything you create. Try it!

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.