Nerdbank.Json
0.1.1010-alpha
Prefix Reserved
dotnet add package Nerdbank.Json --version 0.1.1010-alpha
NuGet\Install-Package Nerdbank.Json -Version 0.1.1010-alpha
<PackageReference Include="Nerdbank.Json" Version="0.1.1010-alpha" />
<PackageVersion Include="Nerdbank.Json" Version="0.1.1010-alpha" />
<PackageReference Include="Nerdbank.Json" />
paket add Nerdbank.Json --version 0.1.1010-alpha
#r "nuget: Nerdbank.Json, 0.1.1010-alpha"
#:package Nerdbank.Json@0.1.1010-alpha
#addin nuget:?package=Nerdbank.Json&version=0.1.1010-alpha&prerelease
#tool nuget:?package=Nerdbank.Json&version=0.1.1010-alpha&prerelease
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, includingList<T>. - Mutable
IDictionary<string, TValue>implementations with public parameterless constructors, includingDictionary<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.BigIntegerDateTime,DateTimeOffset,TimeSpanGuid,Version,Uri,CultureInfo,Encodingbyte[],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 | Versions 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. |
-
.NETFramework 4.7.2
- Microsoft.VisualStudio.Validation (>= 17.13.22)
- Nerdbank.MessagePack (>= 1.2.4)
- PolyType (>= 1.3.1)
- System.Buffers (>= 4.6.1)
- System.IO.Pipelines (>= 10.0.10)
- System.Memory (>= 4.6.3)
-
.NETStandard 2.0
- Microsoft.VisualStudio.Validation (>= 17.13.22)
- Nerdbank.MessagePack (>= 1.2.4)
- PolyType (>= 1.3.1)
- System.Buffers (>= 4.6.1)
- System.IO.Pipelines (>= 10.0.10)
- System.Memory (>= 4.6.3)
-
net8.0
- Microsoft.VisualStudio.Validation (>= 17.13.22)
- Nerdbank.MessagePack (>= 1.2.4)
- PolyType (>= 1.3.1)
- System.IO.Pipelines (>= 10.0.10)
-
net9.0
- Microsoft.VisualStudio.Validation (>= 17.13.22)
- Nerdbank.MessagePack (>= 1.2.4)
- PolyType (>= 1.3.1)
- System.IO.Pipelines (>= 10.0.10)
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 |