Nerdbank.Json 0.1.1010-alpha

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

Nerdbank.Json

Nerdbank.Json is a UTF-8 JSON serializer being built in the same general shape as Nerdbank.MessagePack, but without layering on top of System.Text.Json, Newtonsoft.Json, or any other serializer.

The current implementation includes a low-level writer/reader pair, a built-in converter table for common .NET types, and an initial PolyType-backed object serializer for mutable object graphs. It is allocation-conscious in the hot path and multi-targets net8.0, net9.0, net472, and netstandard2.0.

Features

  • Direct UTF-8 JSON writing to IBufferWriter<byte>.
  • RFC 8259 string escaping, limited to the characters that must be escaped.
  • Built-in serialization and deserialization for common .NET primitive and BCL types.
  • PolyType-driven serialization for object graphs with settable properties.
  • Mutable ICollection<T> implementations with public parameterless constructors, including List<T>.
  • Mutable IDictionary<string, TValue> implementations with public parameterless constructors, including Dictionary<string, TValue>.
  • camelCase property naming by default, configurable with JsonNamingPolicy.
  • Optional indented output for human-readable JSON.
  • Optional case-insensitive property-name matching during deserialization.
  • Optional enum-name serialization with numeric fallback for unnamed values.
  • Runtime custom converter registration with converter instances, converter types, or converter factories.
  • Attribute-driven custom converter registration on types, properties, and constructor parameters.
  • Optional unknown-member retention through JsonExtensionDataAttribute.
  • Built-in byte buffer handling using Base64 JSON strings.
  • Optional trailing-comma and comment skipping support during deserialization.
  • Configurable deserialization policy for missing required values and non-nullable reference validation.
  • Optional acyclic reference preservation.
  • Synchronous stream and async stream overloads.
  • Multi-targeting across modern .NET and .NET Framework.
  • Test-driven development with focused round-trip coverage for the current built-in type surface.

Supported Built-In Types

The current built-in serializer supports:

  • string, char, bool
  • Numeric primitives: byte, sbyte, short, ushort, int, uint, long, ulong, float, double, decimal
  • System.Numerics.BigInteger
  • DateTime, DateTimeOffset, TimeSpan
  • Guid, Version, Uri, CultureInfo, Encoding
  • byte[], Memory<byte>, ReadOnlyMemory<byte>
  • System.Drawing.Color, System.Drawing.Point
  • On .NET 8 and later: Half, Int128, UInt128, DateOnly, TimeOnly, Rune

Example

using Nerdbank.Json;

JsonSerializer serializer = new();

string json = serializer.Serialize(new DateTimeOffset(2024, 7, 1, 12, 34, 56, TimeSpan.Zero));
DateTimeOffset value = serializer.Deserialize<DateTimeOffset>(json);

For mutable object graphs, annotate your root type with GenerateShape and use the same serializer APIs:

using Nerdbank.Json;
using PolyType;

[GenerateShape]
public partial class Person
{
	public string? Name { get; set; }
	public int Age { get; set; }
}

JsonSerializer serializer = new();
string json = serializer.Serialize(new Person { Name = "Ada", Age = 37 });
Person person = serializer.Deserialize<Person>(json);

By default, object property names serialize as camelCase. To preserve declared member names or apply a different built-in transform:

JsonSerializer serializer = new()
{
	PropertyNamingPolicy = JsonNamingPolicy.SnakeLowerCase,
};

This naming policy applies to object property names. Dictionary keys remain unchanged by default. To opt into dictionary key transformation separately:

JsonSerializer serializer = new()
{
	DictionaryKeyNamingPolicy = JsonNamingPolicy.CamelCase,
};

To attach a converter directly to a type or member instead of registering it globally:

[JsonConverter(typeof(MyValueConverter))]
public partial class MyValue
{
	public string? Name { get; set; }
}

To accept more human-authored JSON during deserialization:

JsonSerializer serializer = new()
{
	AllowTrailingCommas = true,
	ReadCommentHandling = JsonCommentHandling.Skip,
};

To retain and re-emit JSON properties that your type does not model yet:

[GenerateShape]
public partial class Person
{
	public string? Name { get; set; }

	[JsonExtensionData]
	public Dictionary<string, string>? ExtensionData { get; set; }
}
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 is compatible.  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 netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 is compatible.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  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 (1)

Showing the top 1 NuGet packages that depend on Nerdbank.Json:

Package Downloads
Nerdbank.Json.AspNetCoreMvcFormatter

ASP.NET Core MVC input and output formatters backed by Nerdbank.Json, enabling AOT-safe, source-generated JSON in MVC and minimal-hosting Web APIs with an explicitly supplied ITypeShapeProvider.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.1.1010-alpha 69 9/1/2026