SystemTextJsonPatch 1.0.0

.NET 6.0 .NET Standard 2.0
dotnet add package SystemTextJsonPatch --version 1.0.0
NuGet\Install-Package SystemTextJsonPatch -Version 1.0.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="SystemTextJsonPatch" Version="1.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add SystemTextJsonPatch --version 1.0.0
#r "nuget: SystemTextJsonPatch, 1.0.0"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. Copy this into the interactive tool or source code of the script to reference the package.
// Install SystemTextJsonPatch as a Cake Addin
#addin nuget:?package=SystemTextJsonPatch&version=1.0.0

// Install SystemTextJsonPatch as a Cake Tool
#tool nuget:?package=SystemTextJsonPatch&version=1.0.0

SystemTextJsonPatchLogo

CI status Nuget

SystemTextJsonPatch

SystemTextJsonPatch is a JSON Patch (JsonPatchDocument) RFC 6902 implementation for .NET using System.Text.Json

This library tries to ease the migration from Newtonsoft.Json to System.Text.Json by providing similar API for HttpPatch requests as in Microsoft.AspNetCore.JsonPatch and Marvin.JsonPatch

  • Designed as an easy replacement for Microsoft.AspNetCore.JsonPatch
  • Supports .NET 6 & netstandard2.0

Getting started

To enable JsonPatchDocument serialization support add SystemTextJsonPatch.Converters.JsonPatchDocumentConverterFactory to System.Text.Json serialization options converters. This is typically done in startup.cs file when configuring Asp.Net core MVC settings


public void ConfigureServices(IServiceCollection services)
{
    services
        .AddControllers()
        .AddJsonOptions((options) =>
        {
            options.JsonSerializerOptions.Converters.Add(new SystemTextJsonPatch.Converters.JsonPatchDocumentConverterFactory());
        });
}

or when using System.Text.Json.JsonSerializer directly with custom settings.

    var jsonOptions = new JsonSerializerOptions()
    {
        Converters =
        {
            new SystemTextJsonPatch.Converters.JsonPatchDocumentConverterFactory()
        }
    };

    var json = System.Text.Json.JsonSerializer.JsonSerializer.Serialize(incomingOperations, jsonOptions);

Performance comparison

This test deserializes a JSON patch document of 8 operations and applies the changes to a new model.

See SystemTextJsonPatch.Benchmark for more details.

BenchmarkDotNet=v0.13.2, OS=Windows 11 (10.0.22000.978/21H2) AMD Ryzen 9 5950X, 1 CPU, 32 logical and 16 physical cores .NET SDK=7.0.100-rc.1.22431.12 [Host] : .NET 6.0.9 (6.0.922.41905), X64 RyuJIT AVX2 Job-URORCR : .NET 6.0.9 (6.0.922.41905), X64 RyuJIT AVX2

WarmupCount=2

Method Mean Error StdDev Gen0 Gen1 Allocated
SystemTextJsonPatch 7.233 us 0.0381 us 0.0356 us 0.3738 - 6.16 KB
MarvinJsonPatch 979.525 us 9.9310 us 8.8036 us 5.8594 3.9063 98.13 KB
AspNetCoreJsonPatch 26.645 us 0.2023 us 0.1892 us 2.5940 0.0610 42.49 KB
Product Versions
.NET net5.0 net5.0-windows net6.0 net6.0-android net6.0-ios net6.0-maccatalyst net6.0-macos net6.0-tvos net6.0-windows net7.0 net7.0-android net7.0-ios net7.0-maccatalyst net7.0-macos net7.0-tvos net7.0-windows
.NET Core netcoreapp2.0 netcoreapp2.1 netcoreapp2.2 netcoreapp3.0 netcoreapp3.1
.NET Standard netstandard2.0 netstandard2.1
.NET Framework net461 net462 net463 net47 net471 net472 net48
MonoAndroid monoandroid
MonoMac monomac
MonoTouch monotouch
Tizen tizen40 tizen60
Xamarin.iOS xamarinios
Xamarin.Mac xamarinmac
Xamarin.TVOS xamarintvos
Xamarin.WatchOS xamarinwatchos
Compatible target framework(s)
Additional computed target framework(s)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on SystemTextJsonPatch:

Package Downloads
SystemTextJsonPatch.AspNet

SystemTextJsonPatch.AspNet contains JsonOptions extensions for ASP.NET Core

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.0 1,037 10/2/2022
0.0.9 2,424 9/11/2022
0.0.8 1,251 8/11/2022
0.0.7 1,345 6/17/2022
0.0.6 168 6/17/2022
0.0.5 1,434 5/24/2022
0.0.4 164 5/24/2022
0.0.3 166 5/23/2022
0.0.2 174 5/23/2022
0.0.1 276 5/19/2022