Skip to content

Commit 57d4db4

Browse files
committed
Applied changes per tdystra recommendations
1 parent 766520f commit 57d4db4

File tree

1 file changed

+16
-22
lines changed

1 file changed

+16
-22
lines changed

aspnetcore/web-api/jsonpatch.md

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,43 +8,39 @@ ms.custom: mvc
88
ms.date: 06/03/2025
99
uid: web-api/jsonpatch
1010
---
11-
# JsonPatch in ASP.NET Core web API
11+
# JSON Patch support in ASP.NET Core web API
1212

1313
:::moniker range=">= aspnetcore-10.0"
1414

1515
This article explains how to handle JSON Patch requests in an ASP.NET Core web API.
1616

17-
JSON Patch support in ASP.NET Core web API is based on <xref:System.Text.Json> serialization, and requires the [`Microsoft.AspNetCore.JsonPatch.SystemTextJson`](https://www.nuget.org/packages/Microsoft.AspNetCore.JsonPatch.SystemTextJson) NuGet package.
17+
JSON Patch support in ASP.NET Core web API is based on <xref:System.Text.Json> serialization, and requires the [`Microsoft.AspNetCore.JsonPatch.SystemTextJson`](https://www.nuget.org/packages/Microsoft.AspNetCore.JsonPatch.SystemTextJson) NuGet package.
1818

19-
**[JSON Patch](https://jsonpatch.com/)**:
19+
## What is the JSON Patch standard?
20+
21+
The JSON Patch standard:
2022

2123
* Is a standard format for describing changes to apply to a JSON document.
22-
* Is defined in [RFC 6902] and is widely used in RESTful APIs to perform partial updates to JSON resources.
24+
* Is defined in [RFC 6902](https://datatracker.ietf.org/doc/html/rfc6902) and is widely used in RESTful APIs to perform partial updates to JSON resources.
2325
* Describes a sequence of operations such as `add`, `remove`, `replace`, `move`, `copy`, and `test` that modify a JSON document.
2426

2527
In web apps, JSON Patch is commonly used in a PATCH operation to perform partial updates of a resource. Rather than sending the entire resource for an update, clients can send a JSON Patch document containing only the changes. Patching reduces payload size and improves efficiency.
2628

27-
JSON Patch support in ASP.NET Core web API is based on <xref:System.Text.Json> serialization, starting with .NET 10. This release introduces a new implementation of <xref:Microsoft.AspNetCore.JsonPatch> based on <xref:System.Text.Json> serialization. This feature:
28-
29-
* Aligns with modern .NET practices by leveraging the <xref:System.Text.Json> library, which is optimized for .NET.
30-
* Provides improved performance and reduced memory usage compared to the legacy `Newtonsoft.Json`-based implementation. For more information on the legacy `Newtonsoft.Json`-based implementation, see the [.NET 9 version of this article](xref:web-api/jsonpatch?view=aspnetcore-9.0&preserve-view=true).
29+
For an overview of the JSON Patch standard, see [jsonpatch.com](https://jsonpatch.com/).
3130

32-
The following benchmarks compare the performance of the new <xref:System.Text.Json> implementation with the legacy `Newtonsoft.Json` implementation:
31+
## JSON Patch support in ASP.NET Core web API
3332

34-
| Scenario | Implementation | Mean | Allocated Memory |
35-
|----------------------------|------------------------|------------|------------------|
36-
| **Application Benchmarks** | Newtonsoft.JsonPatch | 271.924 µs | 25 KB |
37-
| | System.Text.JsonPatch | 1.584 µs | 3 KB |
38-
| **Deserialization Benchmarks** | Newtonsoft.JsonPatch | 19.261 µs | 43 KB |
39-
| | System.Text.JsonPatch | 7.917 µs | 7 KB |
33+
JSON Patch support in ASP.NET Core web API is based on <xref:System.Text.Json> serialization, starting with .NET 10, implementing <xref:Microsoft.AspNetCore.JsonPatch> based on <xref:System.Text.Json> serialization. This feature:
4034

41-
These benchmarks highlight significant performance gains and reduced memory usage with the new implementation.
35+
* Requires the [`Microsoft.AspNetCore.JsonPatch.SystemTextJson`](https://www.nuget.org/packages/Microsoft.AspNetCore.JsonPatch.SystemTextJson) NuGet package.
36+
* Aligns with modern .NET practices by leveraging the <xref:System.Text.Json> library, which is optimized for .NET.
37+
* Provides improved performance and reduced memory usage compared to the legacy `Newtonsoft.Json`-based implementation. For more information on the legacy `Newtonsoft.Json`-based implementation, see the [.NET 9 version of this article](xref:web-api/jsonpatch?view=aspnetcore-9.0&preserve-view=true).
4238

4339
> [!NOTE]
44-
> The new implementation of <xref:Microsoft.AspNetCore.JsonPatch> based on <xref:System.Text.Json?displayProperty=fullName> serialization isn't a drop-in replacement for the legacy `Newtonsoft.Json`-based implementation. It doesn't support dynamic types, for example <xref:System.Dynamic.ExpandoObject>.
40+
> The implementation of <xref:Microsoft.AspNetCore.JsonPatch> based on <xref:System.Text.Json?displayProperty=fullName> serialization isn't a drop-in replacement for the legacy `Newtonsoft.Json`-based implementation. It doesn't support dynamic types, for example <xref:System.Dynamic.ExpandoObject>.
4541
4642
> [!IMPORTANT]
47-
> The JSON Patch standard has ***inherent security risks***. Since these risks are inherent to the JSON Patch standard, the new implementation ***doesn't attempt to mitigate inherent security risks***. It's the responsibility of the developer to ensure that the JSON Patch document is safe to apply to the target object. For more information, see the [Mitigating Security Risks](#mitigating-security-risks) section.
43+
> The JSON Patch standard has ***inherent security risks***. Since these risks are inherent to the JSON Patch standard, the ASP.NET Core implementation ***doesn't attempt to mitigate inherent security risks***. It's the responsibility of the developer to ensure that the JSON Patch document is safe to apply to the target object. For more information, see the [Mitigating Security Risks](#mitigating-security-risks) section.
4844
4945
## Enable JSON Patch support with <xref:System.Text.Json>
5046

@@ -255,9 +251,7 @@ When using the `Microsoft.AspNetCore.JsonPatch.SystemTextJson` package, it's cri
255251
> [!IMPORTANT]
256252
> ***This is not an exhaustive list of threats.*** App developers must conduct their own threat model reviews to determine an app-specific comprehensive list and come up with appropriate mitigations as needed. For example, apps which expose collections to patch operations should consider the potential for algorithmic complexity attacks if those operations insert or remove elements at the beginning of the collection.
257253
258-
By running comprehensive threat models for their own apps and addressing identified threats while following the recommended mitigations below, consumers of these packages can integrate JSON Patch functionality into their apps while minimizing security risks.
259-
260-
Consumers of these packages can integrate JSON Patch functionality into their apps while minimizing security risks, including:
254+
To minimize security risks when integrating JSON Patch functionality into their apps, developers should:
261255

262256
* Run comprehensive threat models for their own apps.
263257
* Address identified threats.
@@ -286,7 +280,7 @@ public void Validate(JsonPatchDocument<T> patch)
286280

287281
### Business Logic Subversion
288282

289-
* **Scenario**: Patch operations can manipulate fields with implicit invariants, (for example, internal flags, IDs, or computed fields), violating business constraints.
283+
* **Scenario**: Patch operations can manipulate fields with implicit invariants (for example, internal flags, IDs, or computed fields), violating business constraints.
290284
* **Impact**: Data integrity issues and unintended app behavior.
291285
* **Mitigation**:
292286
* Use POCOs (Plain Old CLR Objects) with explicitly defined properties that are safe to modify.

0 commit comments

Comments
 (0)