C# tip: quickly generate C# classes from JSON sample data

Posted: (EET/GMT+2)

 

I'm constantly working with ASP.NET web applications, and today, JSON based data is often the way to go. Sometimes, you end up in a situation where you have a piece of JSON data, and you would need to quickly create suitable C# classes to contain information in that data.

Of course, you could do this manually, and for trivial cases this is often fine, but if you have a 25 KiB JSON data file, the process can become unwieldy. Luckily, there's a nice CodePlex project that can help you out: the JSON C# Class Generator. This is a useful standalone application, which runs on your desktop.

However, sometimes you'd need to just quickly convert some JSON data to C# classes, without downloading or installing anything. And yes, there's web version of this same utility available at json2csharp.com.

This web version is a port of the same open-source code to a web application, and this appears to work fine, too.

In case you have similar needs than I did, be sure to check these two links out.

Oh, if you need to validate your JSON data, check out JSONLint.

Good luck!