Microsoft.AspNetCore.JsonPatch
10.0.0-preview.1.25120.3
Prefix Reserved
dotnet add package Microsoft.AspNetCore.JsonPatch --version 10.0.0-preview.1.25120.3
NuGet\Install-Package Microsoft.AspNetCore.JsonPatch -Version 10.0.0-preview.1.25120.3
<PackageReference Include="Microsoft.AspNetCore.JsonPatch" Version="10.0.0-preview.1.25120.3" />
paket add Microsoft.AspNetCore.JsonPatch --version 10.0.0-preview.1.25120.3
#r "nuget: Microsoft.AspNetCore.JsonPatch, 10.0.0-preview.1.25120.3"
// Install Microsoft.AspNetCore.JsonPatch as a Cake Addin #addin nuget:?package=Microsoft.AspNetCore.JsonPatch&version=10.0.0-preview.1.25120.3&prerelease // Install Microsoft.AspNetCore.JsonPatch as a Cake Tool #tool nuget:?package=Microsoft.AspNetCore.JsonPatch&version=10.0.0-preview.1.25120.3&prerelease
About
Microsoft.AspNetCore.JsonPatch
provides ASP.NET Core support for JSON PATCH requests.
How to Use
To use Microsoft.AspNetCore.JsonPatch
, follow these steps:
Installation
dotnet add package Microsoft.AspNetCore.JsonPatch
dotnet add package Microsoft.AspNetCore.Mvc.NewtonsoftJson
Configuration
To enable JSON Patch support, call AddNewtonsoftJson
in your ASP.NET Core app's Program.cs
:
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddControllers()
.AddNewtonsoftJson();
Configure when using System.Text.Json
To add support for JSON Patch using Newtonsoft.Json
while continuing to use System.Text.Json
for other input and output formatters:
- Update your
Program.cs
with logic to construct aNewtonsoftJsonPatchInputFormatter
:static NewtonsoftJsonPatchInputFormatter GetJsonPatchInputFormatter() { var builder = new ServiceCollection() .AddLogging() .AddMvc() .AddNewtonsoftJson() .Services.BuildServiceProvider(); return builder .GetRequiredService<IOptions<MvcOptions>>() .Value .InputFormatters .OfType<NewtonsoftJsonPatchInputFormatter>() .First(); }
- Configure the input formatter:
var builder = WebApplication.CreateBuilder(args); builder.Services.AddControllers(options => { options.InputFormatters.Insert(0, GetJsonPatchInputFormatter()); });
Usage
To define an action method for a JSON Patch in an API controller:
- Annotate it with the
HttpPatch
attribute - Accept a
JsonPatchDocument<TModel>
- Call
ApplyTo
on the patch document to apply changes
For example:
[HttpPatch]
public IActionResult JsonPatchWithModelState(
[FromBody] JsonPatchDocument<Customer> patchDoc)
{
if (patchDoc is not null)
{
var customer = CreateCustomer();
patchDoc.ApplyTo(customer, ModelState);
if (!ModelState.IsValid)
{
return BadRequest(ModelState);
}
return new ObjectResult(customer);
}
else
{
return BadRequest(ModelState);
}
}
In a real app, the code would retrieve the data from a store such as a database and update the database after applying the patch.
Additional Documentation
For additional documentation and examples, refer to the official documentation on JSON Patch in ASP.NET Core.
Feedback & Contributing
Microsoft.AspNetCore.JsonPatch
is released as open-source under the MIT license. Bug reports and contributions are welcome at the GitHub repository.
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 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 is compatible. |
.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 is compatible. 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. |
-
.NETFramework 4.6.2
- Microsoft.CSharp (>= 4.7.0)
- Newtonsoft.Json (>= 13.0.3)
-
.NETStandard 2.0
- Microsoft.CSharp (>= 4.7.0)
- Newtonsoft.Json (>= 13.0.3)
-
net10.0
- Microsoft.CSharp (>= 4.7.0)
- Newtonsoft.Json (>= 13.0.3)
NuGet packages (175)
Showing the top 5 NuGet packages that depend on Microsoft.AspNetCore.JsonPatch:
Package | Downloads |
---|---|
Microsoft.AspNetCore.Mvc.Formatters.Json
ASP.NET Core MVC formatters for JSON input and output and for JSON PATCH input using Json.NET. |
|
Microsoft.AspNetCore.Mvc.NewtonsoftJson
ASP.NET Core MVC features that use Newtonsoft.Json. Includes input and output formatters for JSON and JSON PATCH. This package was built from the source code at https://github.com/dotnet/aspnetcore/tree/b225d30209cf027c80b741d04efe1c54f2431b3c |
|
Microsoft.AspNetCore.App
Provides a default set of APIs for building an ASP.NET Core application. This package requires the ASP.NET Core runtime. This runtime is installed by the .NET Core SDK, or can be acquired separately using installers available at https://aka.ms/dotnet-download. |
|
Microsoft.AspNetCore.All
Provides a default set of APIs for building an ASP.NET Core application, and also includes API for third-party integrations with ASP.NET Core. This package requires the ASP.NET Core runtime. This runtime is installed by the .NET Core SDK, or can be acquired separately using installers available at https://aka.ms/dotnet-download. |
|
RavenDB.Client
RavenDB Client is the client library for accessing RavenDB |
GitHub repositories (48)
Showing the top 5 popular GitHub repositories that depend on Microsoft.AspNetCore.JsonPatch:
Repository | Stars |
---|---|
aspnet/Mvc
[Archived] ASP.NET Core MVC is a model view controller framework for building dynamic web sites with clean separation of concerns, including the merged MVC, Web API, and Web Pages w/ Razor. Project moved to https://github.com/aspnet/AspNetCore
|
|
ravendb/ravendb
ACID Document Database
|
|
thepirat000/Audit.NET
An extensible framework to audit executing operations in .NET and .NET Core.
|
|
asynkron/protoactor-dotnet
Proto Actor - Ultra fast distributed actors for Go, C# and Java/Kotlin
|
|
emberstack/kubernetes-reflector
Custom Kubernetes controller that can be used to replicate secrets, configmaps and certificates.
|
Version | Downloads | Last updated | |
---|---|---|---|
10.0.0-preview.1.25120.3 | 283 | 2/25/2025 | |
9.0.2 | 215,778 | 2/11/2025 | |
9.0.1 | 564,925 | 1/14/2025 | |
9.0.0 | 1,578,702 | 11/12/2024 | |
9.0.0-rc.2.24474.3 | 15,047 | 10/8/2024 | |
9.0.0-rc.1.24452.1 | 9,959 | 9/10/2024 | |
9.0.0-preview.7.24406.2 | 4,054 | 8/13/2024 | |
9.0.0-preview.6.24328.4 | 14,543 | 7/9/2024 | |
9.0.0-preview.5.24306.11 | 1,678 | 6/11/2024 | |
9.0.0-preview.4.24267.6 | 2,445 | 5/21/2024 | |
9.0.0-preview.3.24172.13 | 9,835 | 4/11/2024 | |
9.0.0-preview.2.24128.4 | 3,299 | 3/12/2024 | |
9.0.0-preview.1.24081.5 | 3,022 | 2/13/2024 | |
8.0.13 | 310,848 | 2/11/2025 | |
8.0.12 | 987,213 | 1/14/2025 | |
8.0.11 | 3,514,207 | 11/12/2024 | |
8.0.10 | 5,413,536 | 10/8/2024 | |
8.0.8 | 7,590,493 | 8/13/2024 | |
8.0.7 | 5,353,708 | 7/9/2024 | |
8.0.6 | 5,740,477 | 5/28/2024 | |
8.0.5 | 2,057,301 | 5/14/2024 | |
8.0.4 | 5,545,447 | 4/9/2024 | |
8.0.3 | 4,367,232 | 3/12/2024 | |
8.0.2 | 4,293,805 | 2/13/2024 | |
8.0.1 | 6,350,924 | 1/9/2024 | |
8.0.0 | 13,394,573 | 11/14/2023 | |
8.0.0-rc.2.23480.2 | 57,656 | 10/10/2023 | |
8.0.0-rc.1.23421.29 | 35,108 | 9/12/2023 | |
8.0.0-preview.7.23375.9 | 19,272 | 8/8/2023 | |
8.0.0-preview.6.23329.11 | 15,159 | 7/11/2023 | |
8.0.0-preview.5.23302.2 | 10,364 | 6/13/2023 | |
8.0.0-preview.4.23260.4 | 225,784 | 5/16/2023 | |
8.0.0-preview.3.23177.8 | 30,600 | 4/11/2023 | |
8.0.0-preview.2.23153.2 | 18,238 | 3/14/2023 | |
8.0.0-preview.1.23112.2 | 15,593 | 2/21/2023 | |
7.0.20 | 486,684 | 5/28/2024 | |
7.0.19 | 108,650 | 5/14/2024 | |
7.0.18 | 208,166 | 4/9/2024 | |
7.0.17 | 252,630 | 3/12/2024 | |
7.0.16 | 346,418 | 2/13/2024 | |
7.0.15 | 675,407 | 1/9/2024 | |
7.0.14 | 1,693,680 | 11/14/2023 | |
7.0.13 | 1,980,960 | 10/24/2023 | |
7.0.12 | 1,164,455 | 10/10/2023 | |
7.0.11 | 2,057,761 | 9/12/2023 | |
7.0.10 | 2,520,616 | 8/8/2023 | |
7.0.9 | 1,962,113 | 7/11/2023 | |
7.0.8 | 1,595,896 | 6/22/2023 | |
7.0.7 | 1,263,121 | 6/13/2023 | |
7.0.5 | 6,051,843 | 4/11/2023 | |
7.0.4 | 2,544,986 | 3/14/2023 | |
7.0.3 | 2,700,179 | 2/14/2023 | |
7.0.2 | 3,498,536 | 1/10/2023 | |
7.0.1 | 3,384,480 | 12/13/2022 | |
7.0.0 | 13,169,459 | 11/7/2022 | |
7.0.0-rc.2.22476.2 | 64,779 | 10/11/2022 | |
7.0.0-rc.1.22427.2 | 12,457 | 9/14/2022 | |
7.0.0-preview.7.22376.6 | 14,688 | 8/9/2022 | |
7.0.0-preview.6.22330.3 | 7,230 | 7/12/2022 | |
7.0.0-preview.5.22303.8 | 10,999 | 6/14/2022 | |
7.0.0-preview.4.22251.1 | 18,095 | 5/10/2022 | |
7.0.0-preview.3.22178.4 | 3,774 | 4/13/2022 | |
7.0.0-preview.2.22153.2 | 12,205 | 3/14/2022 | |
7.0.0-preview.1.22109.13 | 21,269 | 2/17/2022 | |
6.0.36 | 344,183 | 11/12/2024 | |
6.0.35 | 295,940 | 10/8/2024 | |
6.0.33 | 1,125,658 | 8/13/2024 | |
6.0.32 | 553,792 | 7/9/2024 | |
6.0.31 | 624,990 | 5/28/2024 | |
6.0.30 | 245,186 | 5/14/2024 | |
6.0.29 | 862,575 | 4/9/2024 | |
6.0.28 | 838,863 | 3/12/2024 | |
6.0.27 | 2,594,032 | 2/13/2024 | |
6.0.26 | 1,573,207 | 1/9/2024 | |
6.0.25 | 2,956,068 | 11/14/2023 | |
6.0.24 | 1,658,278 | 10/24/2023 | |
6.0.23 | 817,482 | 10/10/2023 | |
6.0.22 | 1,548,061 | 9/12/2023 | |
6.0.21 | 2,168,541 | 8/8/2023 | |
6.0.20 | 2,271,294 | 7/11/2023 | |
6.0.19 | 1,320,187 | 6/22/2023 | |
6.0.18 | 781,708 | 6/13/2023 | |
6.0.16 | 5,835,587 | 4/11/2023 | |
6.0.15 | 2,739,581 | 3/14/2023 | |
6.0.14 | 3,113,310 | 2/14/2023 | |
6.0.13 | 5,138,776 | 1/10/2023 | |
6.0.12 | 4,710,913 | 12/13/2022 | |
6.0.11 | 7,332,806 | 11/7/2022 | |
6.0.10 | 10,085,068 | 10/11/2022 | |
6.0.9 | 7,335,046 | 9/13/2022 | |
6.0.8 | 9,800,773 | 8/9/2022 | |
6.0.7 | 7,874,095 | 7/12/2022 | |
6.0.6 | 6,399,923 | 6/14/2022 | |
6.0.5 | 12,058,916 | 5/10/2022 | |
6.0.4 | 7,461,229 | 4/11/2022 | |
6.0.3 | 8,499,379 | 3/8/2022 | |
6.0.2 | 7,424,458 | 2/8/2022 | |
6.0.1 | 15,916,642 | 12/14/2021 | |
6.0.0 | 16,525,607 | 11/8/2021 | |
6.0.0-rc.2.21480.10 | 71,276 | 10/12/2021 | |
6.0.0-rc.1.21452.15 | 21,825,768 | 9/14/2021 | |
6.0.0-preview.7.21378.6 | 59,370 | 8/10/2021 | |
6.0.0-preview.6.21355.2 | 9,708 | 7/14/2021 | |
6.0.0-preview.5.21301.17 | 10,496 | 6/15/2021 | |
6.0.0-preview.4.21253.5 | 22,050 | 5/24/2021 | |
6.0.0-preview.3.21201.13 | 13,795 | 4/8/2021 | |
6.0.0-preview.2.21154.6 | 46,303 | 3/11/2021 | |
6.0.0-preview.1.21103.6 | 25,282 | 2/12/2021 | |
5.0.17 | 2,390,067 | 5/10/2022 | |
5.0.16 | 326,392 | 4/11/2022 | |
5.0.15 | 740,320 | 3/8/2022 | |
5.0.14 | 560,611 | 2/8/2022 | |
5.0.13 | 3,041,561 | 12/14/2021 | |
5.0.12 | 2,279,645 | 11/7/2021 | |
5.0.11 | 5,432,004 | 10/12/2021 | |
5.0.10 | 7,165,670 | 9/14/2021 | |
5.0.9 | 4,298,190 | 8/10/2021 | |
5.0.8 | 3,866,896 | 7/13/2021 | |
5.0.7 | 4,429,518 | 6/8/2021 | |
5.0.6 | 2,979,671 | 5/11/2021 | |
5.0.5 | 4,343,709 | 4/6/2021 | |
5.0.4 | 3,285,212 | 3/9/2021 | |
5.0.3 | 3,726,736 | 2/9/2021 | |
5.0.2 | 2,973,215 | 1/12/2021 | |
5.0.1 | 3,028,126 | 12/8/2020 | |
5.0.0 | 14,200,332 | 11/9/2020 | |
5.0.0-rc.2.20475.17 | 33,696 | 10/13/2020 | |
5.0.0-rc.1.20451.17 | 21,092 | 9/14/2020 | |
5.0.0-preview.8.20414.8 | 8,071 | 8/25/2020 | |
5.0.0-preview.7.20365.19 | 18,331 | 7/21/2020 | |
5.0.0-preview.6.20312.15 | 9,324 | 6/25/2020 | |
5.0.0-preview.5.20279.2 | 22,631 | 6/10/2020 | |
5.0.0-preview.4.20257.10 | 6,196 | 5/18/2020 | |
5.0.0-preview.3.20215.14 | 7,106 | 4/23/2020 | |
5.0.0-preview.2.20167.3 | 10,711 | 4/2/2020 | |
5.0.0-preview.1.20124.5 | 5,131 | 3/16/2020 | |
3.1.32 | 1,514,805 | 12/13/2022 | |
3.1.31 | 209,008 | 11/8/2022 | |
3.1.30 | 316,761 | 10/11/2022 | |
3.1.29 | 383,218 | 9/13/2022 | |
3.1.28 | 521,939 | 8/9/2022 | |
3.1.27 | 570,703 | 7/12/2022 | |
3.1.26 | 419,380 | 6/14/2022 | |
3.1.25 | 656,122 | 5/10/2022 | |
3.1.24 | 429,282 | 4/11/2022 | |
3.1.23 | 836,149 | 3/8/2022 | |
3.1.22 | 3,224,344 | 12/14/2021 | |
3.1.21 | 1,717,666 | 11/7/2021 | |
3.1.20 | 1,336,990 | 10/11/2021 | |
3.1.19 | 1,304,877 | 9/14/2021 | |
3.1.18 | 1,835,606 | 8/10/2021 | |
3.1.17 | 1,816,754 | 7/13/2021 | |
3.1.16 | 2,344,633 | 6/8/2021 | |
3.1.15 | 2,014,291 | 5/11/2021 | |
3.1.14 | 2,856,726 | 4/6/2021 | |
3.1.13 | 3,131,328 | 3/9/2021 | |
3.1.12 | 2,818,162 | 2/9/2021 | |
3.1.11 | 3,978,931 | 1/12/2021 | |
3.1.10 | 7,322,646 | 11/9/2020 | |
3.1.9 | 7,815,269 | 10/13/2020 | |
3.1.8 | 9,942,753 | 9/8/2020 | |
3.1.7 | 6,841,302 | 8/11/2020 | |
3.1.6 | 7,471,450 | 7/14/2020 | |
3.1.5 | 10,607,662 | 6/9/2020 | |
3.1.4 | 7,318,582 | 5/12/2020 | |
3.1.3 | 13,594,026 | 3/24/2020 | |
3.1.2 | 9,497,984 | 2/18/2020 | |
3.1.1 | 11,247,402 | 1/14/2020 | |
3.1.0 | 9,986,114 | 12/3/2019 | |
3.1.0-preview3.19555.2 | 44,270 | 11/13/2019 | |
3.1.0-preview2.19528.8 | 7,086 | 11/1/2019 | |
3.1.0-preview1.19508.20 | 13,117 | 10/15/2019 | |
3.0.3 | 571,854 | 2/18/2020 | |
3.0.2 | 570,180 | 1/14/2020 | |
3.0.0 | 39,408,231 | 9/23/2019 | |
3.0.0-rc1.19457.4 | 39,923 | 9/16/2019 | |
3.0.0-preview9.19424.4 | 79,914 | 9/4/2019 | |
3.0.0-preview8.19405.7 | 113,606 | 8/13/2019 | |
3.0.0-preview7.19365.7 | 94,877 | 7/23/2019 | |
3.0.0-preview6.19307.2 | 273,258 | 6/12/2019 | |
3.0.0-preview5-19227-01 | 826,845 | 5/6/2019 | |
3.0.0-preview4-19216-03 | 36,903 | 4/18/2019 | |
3.0.0-preview3-19153-02 | 6,174,248 | 3/6/2019 | |
3.0.0-preview-19075-0444 | 21,860 | 1/29/2019 | |
3.0.0-preview-18579-0056 | 4,051 | 12/3/2018 | |
2.3.0 | 273,589 | 1/14/2025 | |
2.2.0 | 201,015,881 | 12/3/2018 | |
2.2.0-preview3-35497 | 104,826 | 10/17/2018 | |
2.2.0-preview2-35157 | 45,052 | 9/12/2018 | |
2.2.0-preview1-35029 | 28,431 | 8/22/2018 | |
2.1.1 | 38,815,198 | 6/18/2018 | |
2.1.0 | 102,496,678 | 5/29/2018 | |
2.1.0-rc1-final | 114,088 | 5/6/2018 | |
2.1.0-preview2-final | 183,316 | 4/10/2018 | |
2.1.0-preview1-final | 163,451 | 2/26/2018 | |
2.0.0 | 81,331,960 | 8/11/2017 | |
2.0.0-preview2-final | 102,749 | 6/27/2017 | |
2.0.0-preview1-final | 32,244 | 5/10/2017 | |
1.1.2 | 8,897,693 | 5/9/2017 | |
1.1.1 | 3,996,424 | 3/6/2017 | |
1.1.0 | 2,928,863 | 11/16/2016 | |
1.1.0-preview1-final | 30,099 | 10/24/2016 | |
1.0.0 | 54,868,076 | 6/27/2016 | |
1.0.0-rc2-final | 182,045 | 5/16/2016 |