⚠️ THIS LIB IS UNDER MAINTENANCE
This lib helps you to create a class at runtime from a JSON. It means that you don't need to change your class every time a JSON that you consume has changed.
- Upgrade to .NET 6
You can convert only simple JSON like "{Foo: barValue}".
NEW: you can try to convert this kind of JSON "{'Foo': {Bar1: barValue, Bar2: bar2Value}}".
Use the package manager to install.
Install-Package DotNetJ2Class -Version 1.0.3
After install the package, add this code in your "using" block:
using DotNet.J2Class;
and
string json = @"{'Foo': 'barValue'}";
//You can set a name
//for the class that will be created.
//If you don't pass any name,
//it will be create with DefaultName.
//The same happens with module name.
//Both parameters are optional.
string className = "CLASS_NAME";
string moduleName = "MODULE_NAME"
var myObject = J2Class.CreateObjectFromJson(json, className, moduleName);
//myObject will be like a "className" object with a string property called "Foo" and its value "barValue"
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Please make sure to update tests as appropriate.