ActDim.Practix.Json
1.4.0
dotnet add package ActDim.Practix.Json --version 1.4.0
NuGet\Install-Package ActDim.Practix.Json -Version 1.4.0
<PackageReference Include="ActDim.Practix.Json" Version="1.4.0" />
<PackageVersion Include="ActDim.Practix.Json" Version="1.4.0" />
<PackageReference Include="ActDim.Practix.Json" />
paket add ActDim.Practix.Json --version 1.4.0
#r "nuget: ActDim.Practix.Json, 1.4.0"
#:package ActDim.Practix.Json@1.4.0
#addin nuget:?package=ActDim.Practix.Json&version=1.4.0
#tool nuget:?package=ActDim.Practix.Json&version=1.4.0
ActDim.Practix.Json
ActDim.Practix.Json is a JSON serialization abstraction layer for .NET built on System.Text.Json (STJ). It implements IJsonSerializer, IStringSerializer, IBinarySerializer, and IStreamSerializer through a single CoreJsonSerializer with a rich API covering string/stream/byte serialization (sync and async), JSON merging, deep cloning, object population, and patching. The default options are tuned to match Newtonsoft.Json (Json.NET) behavior out of the box, making migration painless while retaining the speed and low allocation profile of modern STJ.
Why ActDim.Practix.Json? (Painless Newtonsoft.Json Migration)
Migrating legacy codebases from Newtonsoft.Json to standard System.Text.Json is notoriously difficult due to STJ's strict type rules, lack of permissive string parsing, handling of object as JsonElement, and missing declarative policies.
ActDim.Practix.Json bridges this gap by providing full behavioral compatibility with Newtonsoft.Json out of the box while retaining the speed and low memory allocation of modern System.Text.Json.
Default Options: STJ vs Newtonsoft.Json vs Practix.Json
| Setting | Stock STJ | Newtonsoft.Json | Practix.Json | Why |
|---|---|---|---|---|
| Property name matching | Case-sensitive | Case-insensitive | Case-insensitive | JSON keys "name" / "Name" both map to Name |
| Quoted number parsing | Throws | Parses "42" to int |
AllowReadingFromString |
Tolerates upstream APIs that quote numbers |
Named floats (NaN) |
Throws | Parses "NaN" |
AllowNamedFloatingPointLiterals |
IEEE 754 specials survive round-trip |
| Trailing commas | Throws | Allowed | Allowed | Tolerates hand-edited JSON |
| Comments in JSON | Throws | Skipped | Skipped | Tolerates JSON with // comments |
| Encoder | Escapes <>& and non-ASCII |
Raw UTF-8 | UnsafeRelaxedJsonEscaping |
Clean readable output, Cyrillic/CJK unescaped |
| Public fields | Ignored | Serialized | IncludeFields = true |
Fields participate in serialization |
| Circular references | Throws | Throws | IgnoreCycles (writes null) |
Prevents crashes on cyclic object graphs |
object deserialization |
JsonElement |
CLR primitives, JObject | ExpandoObject, List<object>, CLR primitives |
Dynamic access and casting work naturally |
Float .0 suffix |
Strips (7.0 → 7) | Preserves | Preserves via FloatingPointConverterFactory |
Downstream consumers see correct float type |
| Enum serialization | String names | Numeric | Numeric via NumberEnumConverterFactory |
Matches wire format most APIs expect |
| String coercion | Throws on non-string | Coerces | Coerces via NewtonsoftCompatibleStringConverter |
Numbers/bools in string fields don't crash |
Full API Surface
Beyond basic Serialize/Deserialize, CoreJsonSerializer provides operations commonly needed in production but missing from raw STJ:
- Stream serialization (sync and async) - direct
StreamI/O without intermediate string allocation - Byte array serialization - UTF-8 bytes with optional encoding transcoding
- JSON merging (
MergeAndSerialize) - merge multiple object graphs into a single JSON document with configurable array and null handling - Deep cloning (
Clone<T>) - serialize-deserialize round-trip clone - Object population (
Populate<T>) - mutate an existing instance from JSON using compiled Expression Tree property setters - Patching (
Patch<T>) - apply a partial JSON string onto an existing object - Property copying (
Copy<T>) - deep copy values from one instance into another via serialize + populate - Options cloning (
CopyOptions) - copy all settings betweenJsonSerializerOptionsinstances via compiled delegates - Property name formatting (
FormatPropertyName) - transform dot-separated property paths according to the active naming policy
Key Features & STJ Extensions
1. Newtonsoft.Json Compatibility Layer
ObjectJsonConverter(objectas CLR Primitives): Standard STJ deserializesobjectproperties into rawJsonElementstructures. This converter maps them directly into native CLR types (string,long,double,bool,Dictionary<string, object>,List<object>), exactly like Json.NET.NewtonsoftCompatibleStringConverter: Permissively converts numbers, booleans, and nested tokens intostringwithout throwing STJ schema mismatch exceptions.FloatingPointConverterFactory&NumberEnumConverterFactory: Lenient parsing forfloat,double,decimal, and numeric-backedenumtypes (supporting both quoted string numbers and numeric literals).CustomDateTimeConverter: Multi-format permissiveDateTime/DateTimeOffsetparsing across diverse legacy date representations.ImplicitOperatorConverterFactory: Automatically discovers and invokes custom C#implicitconversion operators during deserialization (ideal for Value Objects and Strongly-Typed IDs).ExceptionJsonConverter: Cleanly serializes deep .NETExceptionhierarchies and inner exceptions without circular references or max depth exceptions.RuntimeTypeJsonConverter: Robust polymorphic type serialization supporting dynamic runtime types.
2. Declarative Attributes & Contract Resolvers
[JsonIgnoreEmpty](EmptyCollectionIgnoreResolver): Automatically omits empty collections, lists, arrays, and dictionaries from the serialized JSON output (mirroring Newtonsoft'sDefaultValueHandling.Ignore).[JsonIgnoreDefault]&[JsonDefaultValue(val)](DefaultValueAwareResolver): Ignores properties with default values or assigns declared fallback values when deserializing missing properties.[JsonNaming(namingPolicy)]&NamingPolicyResolver: Granular per-class or per-property naming policy customization, supportingLowerCaseNamingPolicy,UpperCaseNamingPolicy,CamelCase, and custom policies.
3. Extreme Performance with Zero Overhead
- Expression Tree Delegate Compilation: Fast, compiled Expression Trees are used for
CopyOptionsand fast property mutation, eliminating runtime reflection overhead and boxing. - Autonomous & Lightweight: No external reflection libraries or bloated dependencies.
Installation
Install via the .NET CLI:
dotnet add package ActDim.Practix.Json
Or via Package Manager Console:
Install-Package ActDim.Practix.Json
Dependency Injection Setup
Register CoreJsonSerializer as IJsonSerializer, IStringSerializer, IBinarySerializer, and IStreamSerializer:
using ActDim.Practix.Json.Extensions;
using Microsoft.Extensions.DependencyInjection;
public void ConfigureServices(IServiceCollection services)
{
// Registers IJsonSerializer, IStringSerializer, IBinarySerializer, and IStreamSerializer
services.AddCoreJsonSerializer();
}
Quick Start Examples
1. Basic Serialization & Deserialization
using ActDim.Practix.Abstractions.Json;
using Microsoft.Extensions.DependencyInjection;
var serializer = serviceProvider.GetRequiredService<IJsonSerializer>();
var user = new UserProfile
{
Id = 42,
Name = "Alice",
Email = "alice@example.com"
};
// Serialize to JSON string
string json = serializer.Serialize(user);
// Deserialize from JSON string
UserProfile restored = serializer.Deserialize<UserProfile>(json);
2. Painless Newtonsoft.Json Migration Patterns
using ActDim.Practix.Json;
using System.Collections.Generic;
public class ApiResponse
{
// Empty collections are omitted from JSON (like Newtonsoft DefaultValueHandling.Ignore)
[JsonIgnoreEmpty]
public List<string> Warnings { get; set; } = new List<string>();
// Omitted if 0 (default value)
[JsonIgnoreDefault]
public int RetryCount { get; set; } = 0;
// Injects "ACTIVE" if property is missing in input JSON
[JsonDefaultValue("ACTIVE")]
public string Status { get; set; }
// Deserializes into Dictionary/primitives instead of raw JsonElement!
public object DynamicPayload { get; set; }
}
Testing & Quality
- Test Suite:
ActDim.Practix.Json.Tests - Total Tests: 102 passed (100% success rate, 0 failed, 0 skipped)
- Target Framework: .NET 10.0
dotnet test Tests/Json.Tests/ActDim.Practix.Json.Tests.csproj
AI-Assisted Development
Developed with Along - a provider-agnostic context and memory system for AI coding agents.
License
This project is licensed under the MIT License.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. 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. |
-
net10.0
- ActDim.Practix.Abstractions (>= 1.4.0)
- ActDim.Practix.Common (>= 1.4.0)
- Microsoft.Extensions.Caching.Abstractions (>= 10.0.0)
- Microsoft.Extensions.Caching.Memory (>= 10.0.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.0)
- Microsoft.Extensions.Logging.Abstractions (>= 10.0.0)
- Microsoft.Extensions.Options (>= 10.0.0)
- Microsoft.IO.RecyclableMemoryStream (>= 3.0.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.