Pasting JSON/XML as Classes in Visual Studio

REST and JSON together have revolutionised the way we expose and consume data in recent years. For this reason it has become increasingly common to need to integrate with REST services, and data itself is provided in either XML or JSON format. This typically involves creating a set of classes that match the data provided by the service, so that the application may take care of serialisation and deserialisation, and work with structured data.

Although you can create these data classes manually, Visual Studio provides a shortcut to generate classes from XML or JSON data. For instance, let’s say that we want to work with the data from the GitHub API:

We can easily generate a class for this by copying that data, and in Visual Studio going into Edit -> Paste Special -> Parse JSON As Classes: