dotnet / dotnet/aspnetcore

Support for JSON Merge Patch (RFC 7386)

Open
#35,237 4 comments 14 reactions 0 assignees View on GitHub
area-minimal area-mvc area-networking feature-json-patch
Dominant language
C#
Stars
38.4k
Forks
10.9k
Avg merge
2d 5h
Merged PRs (30d)
276

Description

### Is your feature request related to a problem? Please describe.
Implementing JSON Merge Patch manually can be quite tricky but provides a simpler experience for API consumers.

### Describe the solution you'd like
Currently there is built-in support for JSON Patch ([RFC 6902](https://datatracker.ietf.org/doc/html/rfc6902)) via [JsonPatchDocument](https://docs.microsoft.com/en-us/aspnet/core/web-api/jsonpatch?view=aspnetcore-5.0). Would love to also see an implementation of [RFC 7386](https://datatracker.ietf.org/doc/html/rfc7386).

**So no one has to wade through an RFC...**

Given the following JSON representation:

```json
{
"name": "Joe",
"email": "joe@example.com",
"physicalAttributes": { "weight": 75, "height": 175 },
"favoriteColors": ["blue", "red"]
}
```

These two will produce equivalent modifications:

#### JSON Patch

```json
[
{ "op": "remove", "path": "/email" },
{ "op": "add", "path": "/favoriteColors/-", "value": "black" }
]
```

#### JSON Merge Patch

```json
{
"email": null,
"favoriteColors": ["blue", "red", "black"]
}
```

### Additional context
OData has an implementation of this spec via [Delta](https://github.com/OData/AspNetCoreOData/blob/ea6775e7c75c3d198bf86e041bcce27ad4f457db/src/Microsoft.AspNetCore.OData/Deltas/Delta.cs) but it [was not designed](https://stackoverflow.com/a/14734273/3317144) to work with formatters other than OData.

Here are a couple of open-source implementations:
https://www.strathweb.com/2013/01/easy-asp-net-web-api-resource-updates-with-delta/
https://github.com/Morcatko/Morcatko.AspNetCore.JsonMergePatch

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.