C# to JSON

I got tired of writing throw-away code to generate JSON from my C# classes so I built this converter tool.

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

Give it a try! Here's the rules

  • Must supply valid C# code, ideally just the classes/objects that make up your models (no main() function or any other app startup code necessary - it will be ignored).
  • If a class depends on other object types, include those dependency classes too.
  • If you want your JSON to be populated with sample data, initialize those properties in a constructor, otherwise you'll get null/default values.
  • If you want a class excluded from your JSON, create a default constructor for that class and mark it as private.
  • If it doesn't compile in Visual Studio it won't compile here.
See the example below and try it out.
Note: This tool is intended to consume reasonably simple C# class hierarchies that have no dependencies on external libraries. Anything too complex may generate errors.
   

Options:
  Camel case
  Generate comments
  Minify