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!
You must supply valid C# code, ideally just the classes and/or structs that make up your models. No main() function or any other application code necessary.
The tool will create an instance of each type using its default constructor.
statements (ie. System, System.Collections.Generic, etc.), as well as namespace declarations, are not required,
just the class declarations themselves.
If a class depends on another type, be sure to include the dependency(s) as class definitions.
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.
See example below and try it out.
Note: This tool is only intended to consume reasonably simple C# class hierarchies that have no external dependencies. Anything too complex may generate an error.