DotNetJ2Class 1.1.0
dotnet add package DotNetJ2Class --version 1.1.0
NuGet\Install-Package DotNetJ2Class -Version 1.1.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="DotNetJ2Class" Version="1.1.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="DotNetJ2Class" Version="1.1.0" />
<PackageReference Include="DotNetJ2Class" />
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add DotNetJ2Class --version 1.1.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: DotNetJ2Class, 1.1.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package DotNetJ2Class@1.1.0
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=DotNetJ2Class&version=1.1.0
#tool nuget:?package=DotNetJ2Class&version=1.1.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
⚠️ THIS LIB IS UNDER MAINTENANCE
DotNet.J2Class
DotNet.J2Class generates plain .NET POCO types at runtime from JSON payloads using Reflection.Emit. It's useful for quickly mapping unknown or evolving JSON schemas into runtime-accessible objects without maintaining static DTOs.
Quick highlights
- Runtime type generation using
TypeBuilder/PropertyBuilderandILGenerator. - Supports nested objects and arrays (primitive and object arrays are handled).
- Caches generated types by schema signature to avoid re-emitting identical types.
Getting started
Install (NuGet):
Install-Package DotNetJ2Class
Basic usage
using DotNet.J2Class;
string simple = "{'Foo':'bar'}";
var obj = J2Class.CreateObjectFromJson(simple, "MyClass");
dynamic dyn = obj;
Console.WriteLine(dyn.Foo); // -> bar
string complex = "{'Person': {'Name':'Alice','Age':30}, 'Tags': ['x','y']}";
var obj2 = J2Class.CreateObjectFromComplexJson(complex, "RootClass");
dynamic d2 = obj2;
Console.WriteLine(d2.Person.Name); // -> Alice
Commands
dotnet build
dotnet test
dotnet run --project test/ConsoleApp1
Important notes / gotchas
- The project targets
net9.0(seesrc/DotNet.J2Class/DotNet.J2Class.csproj). - Parsing: inputs using single quotes are normalized internally, but prefer valid JSON (double quotes) for robustness.
- Arrays: homogeneous primitive arrays are materialized as typed
List<T>(e.g.List<string>); mixed or empty arrays fall back toList<object>. - Exceptions:
CreateObjectFromJsonwraps failures inInvalidOperationExceptionto surface errors;CreateObjectFromComplexJsonpreserves thrown exceptions for easier debugging in some paths. - Caching: generated types are cached by a schema signature — this improves performance but increases runtime memory usage for many distinct schemas.
Testing
- Tests live in
test/DotNet.J2Class.Testsand use NUnit. They cover simple, complex, array, concurrency and basic performance scenarios.
Contributing
- PRs welcome. For larger changes open an issue first.
- When changing parsing or type generation, add tests in
test/DotNet.J2Class.Testsdemonstrating expected behaviors.
License
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net9.0
- Microsoft.CSharp (>= 4.7.0)
- Newtonsoft.Json (>= 13.0.1)
- System.Reflection.Emit (>= 4.7.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Beta Version