Visual Studio > Paste as JSON

JSON is becoming increasingly more popular, it seems like it might be edging XML out as a method for transporting data. 

It happens more and more that I need to be able to create a set of classes to represent a JSON file, so that I can work with it in .NET. 

In other words, I have this JSON:

{
"id": "0001",
"type": "donut",
"name": "Cake",
"image":
{
"url": "images/0001.jpg",
"width": 200,
"height": 200
},
"thumbnail":
{
"url": "images/thumbnails/0001.jpg",
"width": 32,
"height": 32
}
}

and I need this set of classes:

public class Rootobject
{
    public string id { get; set; }
    public string type { get; set; }
    public string name { get; set; }
    public Image image { get; set; }
    public Thumbnail thumbnail { get; set; }
}
 
public class Image
{
    public string url { get; set; }
    public int width { get; set; }
    public int height { get; set; }
}
 
public class Thumbnail
{
    public string url { get; set; }
    public int width { get; set; }
    public int height { get; set; }
}

It turns out that Visual Studio will do this AUTOMATICALLY. Who knew?

Just get the JSON on your clipboard and do this. Try it!

 

 


RealWorldCode gives developers practical, real‑world solutions with clean, working code — no fluff, no theory, just answers.
Links
Home
Knowledge Areas
Sitemap
Contact
Et cetera
Privacy Policy
Terms and Conditions
Cookie Preferences