joao2391 / DotNetJ2Class

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.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

DotNet.J2Class Nuget Nuget

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.

Notes

  • Upgrade to .NET 6

BETA Version

You can convert only simple JSON like "{Foo: barValue}".
NEW: you can try to convert this kind of JSON "{'Foo': {Bar1: barValue, Bar2: bar2Value}}".

Installation

Use the package manager to install.

Install-Package DotNetJ2Class -Version 1.0.3

Usage

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" 

Contributing

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.

License

MIT

About

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.


Languages

Language:C# 100.0%