Visual Studio 2013 - Paste JSON as Class
There is a really cool new feature in Visual Studio 2013 that lets you paste JSON or XML and create a class hierarchy from it. For example, if you have the following JSON:
{
"People" :[{
"First Name" : "John",
"Last Name" : "Koerner",
"Address" : {
"Street" : "1234 Main",
"City" : "Somewhere",
"State" : "MI",
"Zip" : 12345
}
}]
}
You can open up a .cs file in VS 2013, and under the Edit->Paste Special
menu, you have the option to Paste JSON as Classes
, which will create the following class hierarchy:
public class Rootobject
{
public Person[] People { get; set; }
}
public class Person
{
public string FirstName { get; set; }
public string LastName { get; set; }
public Address Address { get; set; }
}
public class Address
{
public string Street { get; set; }
public string City { get; set; }
public string State { get; set; }
public int Zip { get; set; }
}
Even though this is a really small feature, it's just one of those small things that just makes working in visual studio that much easier.