C# to JSON

I got tired of writing throw-away code to generate JSON representations of my C# model classes (typically for ASP.NET & WebApi applications), so I built this converter tool.

It uses Microsoft “Roslyn” CTP to compile C# code on the fly and then serialize it to JSON.

Give it a try!

You must supply compile-able C# code, ideally just classes. Common using statements (ie. System, System.Collections.Generic, etc.), as well as namespace declarations, are not required, just the class declarations themselves. If one class depends on another, obviously include the dependencies too. If you want your JSON to be populated with sample data, initialize those properties in a constructor. See below for a typical example and try it out.

Note: This tool is only intended to consume reasonably simple C# class hierarchies, anything too complex will probably generate an error.