https://github.com/thorstenhans/jsonpatch.contrib
https://github.com/thorstenhans/jsonpatch.contrib
Last synced: 8 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/thorstenhans/jsonpatch.contrib
- Owner: ThorstenHans
- License: mit
- Created: 2022-09-01T09:57:59.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2022-09-01T12:26:09.000Z (almost 4 years ago)
- Last Synced: 2025-02-15T10:17:44.258Z (over 1 year ago)
- Language: C#
- Size: 12.7 KB
- Stars: 3
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ThorstenHans.JsonPatch.Contrib
[](https://github.com/ThorstenHans/JsonPatch.Contrib/actions/workflows/release.yml)
The main purpose of this NuGet package is to simplify the usage of `JsonPatchDocument` (`Microsoft.AspNetCore.JsonPatch`) when generating JSON patch expressions.
This is especially handy when working with SDKs like for example the official Kubernetes Client SDK for C#.
The package takes care about specifying proper `ContractResolvers` and producing valid JSON patch expressions as `string` by removing unsupported properties before serializing into a string.
```csharp
public class TestModel
{
public string FirstName { get; set; }
public int Age { get; set; }
}
public class Examples
{
public static void Sample1()
{
var doc = JsonPatchDocumentBuilder.BuildFor();
doc.Replace(t => t.FirstName, "John");
doc.Replace(t => t.Age, 42);
var patchString = doc.ToJsonPatch();
Console.WriteLine(patchString);
}
}
```
Invoking `Examples.Sample1()` will print the following string to the console:
```json
[
{
"path":"/firstName",
"op":"replace",
"value":"John"
},
{
"path":"/age",
"op":"replace",
"value":42
}
]
```
## Install via `dotnet` CLI
You can easily install the package using `dotnet` CLI:
```bash
dotnet add package ThorstenHans.JsonPatch.Contrib
```