JsonPatch.Json.Net 1.0.3

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

JsonPatch.Json.Net

This implementation of JsonPatch is targeted towards projects that use Newtonsoft's Json.Net library and would like to manipulate Json documents based on JToken / JObject.

The reason for creating this library is to achieve performance optimizations in the following cases:

  • When json documents are parsed and converted to JTokens for other reasons (e.g. schema validation, or manipulation) and a JsonPatch would need to be applied to them.
  • When a single JsonPatch would need to be applied to multiple documents, and deserializing the same JsonPatch document multiple times would be inefficient.

Usage examples

Executing JsonPatch using json strings

Using exceptions

var originalDocString = "{\"baz\": \"qux\",\"foo\": \"bar\"}";
var patchString = "[{\"op\": \"replace\",\"path\": \"/baz\",\"value\": \"boo\"}]";
var result = JPatch.Patch(originalDocString, patchString);

Returning errors inside a JPatchFailReason class.

var originalDocString = "{\"baz\": \"qux\",\"foo\": \"bar\"}";
var patchString = "[{\"op\": \"replace\",\"path\": \"/baz\",\"value\": \"boo\"}]";
var success = JPatch.TryPatch(originalDocString, patchString, out var resultString, out var patchFailReason);

Executing JsonPatch using JToken objects

This method of execution is the reason why JsonPatch.Json.Net was developed.

Using exceptions

var originalDocString1 = "{\"baz\": \"qux\",\"foo\": \"bar\"}";
var originalDocString2 = "{\"baz\": \"qux\",\"foo\": \"bar\"}";

var patchString = "[{\"op\": \"replace\",\"path\": \"/baz\",\"value\": \"boo\"}]";

var patch = JPatchDocument.Load(patchString);


var originalDoc1 = JToken.Parse(originalDocString1);
var originalDoc2 = JToken.Parse(originalDocString2);


var result1 = JPatch.Patch(originalDoc1, patch);
var result2 = JPatch.Patch(originalDoc2, patch);

Returning errors inside a JPatchFailReason class.

With this method, the patch document is only parsed once, and the patched documents are still in JToken form, ready for further processing, without needing another parsing.

This method of execution returns errors inside a JPatchFailReason class.

var originalDocString1 = "{\"baz\": \"qux\",\"foo\": \"bar\"}";
var originalDocString2 = "{\"baz\": \"qux\",\"foo\": \"bar\"}";

var patchString = "[{\"op\": \"replace\",\"path\": \"/baz\",\"value\": \"boo\"}]";
var patch = JPatchDocument.Load(patchString);

var originalDoc1 = JToken.Parse(originalDocString1);
var originalDoc2 = JToken.Parse(originalDocString2);

var success1 = JPatch.TryPatch(originalDoc1, patch, out var result1, out var patchFailReason1);
var success2 = JPatch.TryPatch(originalDoc2, patch, out var result2, out var patchFailReason2);
Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.3 820 9/10/2023
1.0.1 726 9/9/2023
1.0.0 737 9/8/2023