CSharpEssentials.Json 3.0.1

dotnet add package CSharpEssentials.Json --version 3.0.1
                    
NuGet\Install-Package CSharpEssentials.Json -Version 3.0.1
                    
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="CSharpEssentials.Json" Version="3.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="CSharpEssentials.Json" Version="3.0.1" />
                    
Directory.Packages.props
<PackageReference Include="CSharpEssentials.Json" />
                    
Project file
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 CSharpEssentials.Json --version 3.0.1
                    
#r "nuget: CSharpEssentials.Json, 3.0.1"
                    
#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 CSharpEssentials.Json@3.0.1
                    
#: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=CSharpEssentials.Json&version=3.0.1
                    
Install as a Cake Addin
#tool nuget:?package=CSharpEssentials.Json&version=3.0.1
                    
Install as a Cake Tool

CSharpEssentials.Json

CSharpEssentials.Json provides advanced JSON serialization and deserialization utilities for .NET. It builds on top of System.Text.Json to offer enhanced features like polymorphic serialization, multi-format date handling, and smarter enum conversion.

🚀 Features

  • Conditional String Enums: Automatically serialize enums as strings if they are marked with [StringEnum].
  • Multi-Format Date Conversion: Deserialize dates from a wide variety of formats (ISO 8601, RFC, etc.) seamlessly.
  • Polymorphic Serialization: Built-in support for handling abstract classes and interfaces using a $type discriminator.
  • Enhanced Options: Pre-configured JsonSerializerOptions for modern web standards (CamelCase, IgnoreCycles, etc.).
  • Fluent Extensions: Methods like ConvertToJson() and ConvertFromJson() for quick object-string conversions.

📦 Installation

dotnet add package CSharpEssentials.Json

🛠 Usage

1. Enhanced Serialization Options

Use EnhancedJsonSerializerOptions.DefaultOptions to get a configured set of options that includes all the custom converters.

using CSharpEssentials.Json;
using System.Text.Json;

var options = EnhancedJsonSerializerOptions.DefaultOptions;
string json = JsonSerializer.Serialize(myObject, options);

2. Polymorphic Serialization

Serialize and deserialize class hierarchies automatically. The converter adds a $type property to the JSON to identify the concrete type.

using CSharpEssentials.Json;

public abstract class Animal { public string Name { get; set; } }
public class Dog : Animal { public string Bark { get; set; } }
public class Cat : Animal { public string Meow { get; set; } }

var animals = new List<Animal> { new Dog(), new Cat() };

// Serializes with "$type": "Namespace.Dog"
string json = animals.ConvertToJson(); 

// Deserializes back to specific Dog/Cat types
List<Animal>? result = json.ConvertFromJson<List<Animal>>();

3. Multi-Format Date Handling

The library can deserialize date strings in many different formats without manual configuration.

using CSharpEssentials.Json;

// All these formats work automatically
string[] jsonDates = [
    "\"2024-03-14T15:30:45Z\"",
    "\"14.03.2024\"",
    "\"March 14, 2024\""
];

foreach(var json in jsonDates)
{
    DateTime dt = json.ConvertFromJson<DateTime>();
}

4. String Enum Support

Mark your enums with [StringEnum] (from CSharpEssentials.Enums) to serialize them as strings. Unmarked enums remain as integers (or default behavior).

using CSharpEssentials.Enums;
using CSharpEssentials.Json;

[StringEnum]
public enum Status { Active, Inactive }

public enum Level { Low, High }

var data = new { S = Status.Active, L = Level.High };

// Result: {"s": "Active", "l": 1}
string json = data.ConvertToJson(); 

5. Quick Extensions

Simplify your code with direct conversion methods.

using CSharpEssentials.Json;

var user = new { Name = "Alice", Age = 30 };

// To JSON
string json = user.ConvertToJson();

// From JSON
var parsed = json.ConvertFromJson<dynamic>();

// To JsonDocument
JsonDocument doc = json.ConvertToJsonDocument();
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  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. 
.NET Core netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (5)

Showing the top 5 NuGet packages that depend on CSharpEssentials.Json:

Package Downloads
CSharpEssentials

A comprehensive C# library enhancing functional programming capabilities with type-safe monads (Maybe, Result), discriminated unions (Any), and robust error handling. Features include: domain-driven design support, enhanced Entity Framework integration, testable time management, JSON utilities, and LINQ extensions. Built for modern C# development with focus on maintainability, testability, and functional programming principles.

CSharpEssentials.EntityFrameworkCore

Enhances Entity Framework Core with functional programming patterns and DDD-friendly features. Includes base entity classes, soft delete support, audit trails, query filters, optimistic concurrency, PostgreSQL integration, query performance monitoring, and domain event handling. Perfect for building maintainable and scalable data access layers in modern .NET applications.

CSharpEssentials.AspNetCore

A comprehensive ASP.NET Core library that enhances functional programming capabilities in web applications. Features include API versioning, global exception handling with enhanced problem details, advanced Swagger/OpenAPI configuration, model validation, optimized JSON handling, and seamless integration with CSharpEssentials core functional patterns (Result, Maybe, Rule Engine). Perfect for building robust, maintainable, and type-safe web APIs following functional programming principles.

CSharpEssentials.Results

Result pattern implementation for functional error handling in C#. Provides Result<T> and Result types for railway-oriented programming, eliminating exceptions for expected failures. Foundation for functional programming patterns and robust error handling.

CSharpEssentials.Any

Discriminated union types (Any<T0,T1> to Any<T0,...,T7>) for functional programming in C#. Provides type-safe alternatives to object/dynamic with pattern matching, implicit conversions, and JSON serialization support. Essential for functional programming patterns and type-safe handling of multiple possible types.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
3.0.1 28 5/3/2026
3.0.0 31 5/3/2026
2.1.0 351 11/26/2025
2.0.9 325 9/30/2025
2.0.8 303 9/29/2025
2.0.7 307 9/29/2025
2.0.6 300 9/29/2025
2.0.5 312 9/29/2025
2.0.4 305 9/28/2025
2.0.3 307 9/28/2025
2.0.2 309 9/28/2025
2.0.1 313 9/28/2025
2.0.0 309 9/28/2025