JsonPatch.Net 3.1.1

There is a newer version of this package available.
See the version list below for details.
dotnet add package JsonPatch.Net --version 3.1.1
                    
NuGet\Install-Package JsonPatch.Net -Version 3.1.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="JsonPatch.Net" Version="3.1.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="JsonPatch.Net" Version="3.1.1" />
                    
Directory.Packages.props
<PackageReference Include="JsonPatch.Net" />
                    
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 JsonPatch.Net --version 3.1.1
                    
#r "nuget: JsonPatch.Net, 3.1.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 JsonPatch.Net@3.1.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=JsonPatch.Net&version=3.1.1
                    
Install as a Cake Addin
#tool nuget:?package=JsonPatch.Net&version=3.1.1
                    
Install as a Cake Tool

Summary

JsonPatch.Net implements JSON Patch, RFC 6902, a JSON document structure for expressing a sequence of operations to apply to another JSON document.

Usage

Deserialize and apply immediately:

var patch = JsonSerializer.Deserialize<JsonPatch>(patchString);
var doc = JsonNode.Parse(docString);
var result = patch.Apply(doc);

Or you can build a patch inline:

var patch = new JsonPatch(PatchOperation.Add("/foo/bar", "baz"),
                          PatchOperation.Test("/foo/biz", false));

There is also limited patch generation support:

// parse your data
var start = JsonNode.Parse("[{\"test\":\"test123\"},{\"test\":\"test321\"},{\"test\":[1,2,3]},{\"test\":[1,2,4]}]");
// or build it inline
var target = new JsonArray{
  new JsonObject { ["test"] = "test123" },
  new JsonObject { ["test"] = "test32132" },
  new JsonObject { ["test1"] = "test321" },
  new JsonObject { ["test"] = new JsonArray{ 1, 2, 3 } },
  new JsonObject { ["test"] = new JsonArray{ 1, 2, 3 } },
}

var patch = start.CreatePatch(target);

/*
Result:
[
  {"op":"replace","path":"/1/test","value":"test32132"},
  {"op":"remove","path":"/2/test"},
  {"op":"add","path":"/2/test1","value":"test321"},
  {"op":"replace","path":"/3/test/2","value":3},
  {"op":"add","path":"/4","value":{"test":[1,2,3]}}
]
*/

Sponsorship

If you found this library helpful and would like to promote continued development, please consider sponsoring the maintainers.

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 was computed.  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 was computed.  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 (78)

Showing the top 5 NuGet packages that depend on JsonPatch.Net:

Package Downloads
Aspire.Hosting

Core abstractions for the Aspire application model.

Aspire.Hosting.AppHost

Core library and MSBuild logic for Aspire AppHost projects.

Aspire.Hosting.Azure

Azure resource types for Aspire.

Aspire.Hosting.Testing

Testing support for the Aspire application model.

Aspire.Hosting.SqlServer

Microsoft SQL Server support for Aspire.

GitHub repositories (7)

Showing the top 7 popular GitHub repositories that depend on JsonPatch.Net:

Repository Stars
dotnet/aspire
Aspire is the tool for code-first, extensible, observable dev and deploy.
umbraco/Umbraco-CMS
Umbraco is a free and open source .NET content management system helping you deliver delightful digital experiences.
asynkron/protoactor-dotnet
Proto Actor - Ultra fast distributed actors for Go, C# and Java/Kotlin
kubernetes-client/csharp
Officially supported dotnet Kubernetes Client library
dotnet/dotnet-operator-sdk
KubeOps is a Kubernetes operator sdk in dotnet. Strongly inspired by kubebuilder.
corvus-dotnet/Corvus.JsonSchema
Support for Json Schema validation and entity generation
NosCoreIO/NosCore
NosCore is a Nostale emulator in c# (.Net 9) using DotNetty / Entity Framework / WebAPI / Autofac / Mapster / Serilog
Version Downloads Last Updated
3.3.0 4,610,323 1/2/2025
3.2.3 769,915 12/5/2024
3.2.2 8,307 12/3/2024
3.2.1 1,245 12/3/2024
3.2.0 6,175 11/30/2024
3.1.1 2,560,880 7/2/2024
3.1.0 315,345 5/1/2024
3.0.0.2 122,603 4/19/2024
3.0.0.1 339 4/19/2024
3.0.0 230,785 2/3/2024
2.1.0 836,730 6/12/2023
2.0.6 281,732 3/9/2023
2.0.5 5,772 3/7/2023
2.0.4 427,341 8/20/2022
2.0.3 1,950 8/12/2022
2.0.2 57,616 6/18/2022
2.0.1 21,355 6/16/2022
2.0.0 2,713 6/13/2022
1.1.2 329,020 12/5/2021
1.1.1 3,469 11/11/2021
1.1.0 61,535 9/13/2021
1.0.6 13,485 7/25/2021
1.0.5 2,625 6/20/2021
1.0.4 13,712 1/1/2021
1.0.3 889 12/19/2020
1.0.1 813 10/18/2020
1.0.0 1,452 10/16/2020

Release notes can be found at https://docs.json-everything.net/rn-json-patch/