Jadipa 0.1.2
See the version list below for details.
dotnet add package Jadipa --version 0.1.2
NuGet\Install-Package Jadipa -Version 0.1.2
<PackageReference Include="Jadipa" Version="0.1.2" />
<PackageVersion Include="Jadipa" Version="0.1.2" />
<PackageReference Include="Jadipa" />
paket add Jadipa --version 0.1.2
#r "nuget: Jadipa, 0.1.2"
#:package Jadipa@0.1.2
#addin nuget:?package=Jadipa&version=0.1.2
#tool nuget:?package=Jadipa&version=0.1.2
Jadipa
Jadipa is a .NET binding for the Jadipa JSON DiffPatch core library.
The package applies JSON Patch documents as defined by RFC 6902 to JSON values addressed with JSON Pointer paths as defined by RFC 6901.
Installation
dotnet add package Jadipa
The package targets net10.0 and ships native runtime assets for:
osx-arm64osx-x64linux-x64linux-arm64win-x64
Usage
using Jadipa;
var targetJson = """
{
"title": "Draft release notes",
"status": "draft",
"tags": ["release", "internal"],
"metadata": {
"owner": "core",
"reviewed": false
},
"temporary": true
}
""";
var patchJson = """
[
{ "op": "test", "path": "/status", "value": "draft" },
{ "op": "replace", "path": "/status", "value": "published" },
{ "op": "add", "path": "/tags/-", "value": "json-patch" },
{ "op": "remove", "path": "/temporary" },
{ "op": "copy", "from": "/metadata/owner", "path": "/owner" },
{ "op": "move", "from": "/title", "path": "/headline" }
]
""";
try
{
var patchedJson = Jadipa.Jadipa.ApplyPatchJson(targetJson, patchJson);
Console.WriteLine(patchedJson);
}
catch (JadipaErrorException ex)
{
Console.Error.WriteLine(ex.Message);
}
ApplyPatchJson returns a new compact JSON string. The input JSON string is not modified.
JSON Patch
Patch documents must be JSON arrays. Operations are applied in array order, and application stops at the first failing operation.
Supported operations:
add: inserts or replaces an object member, inserts into an array at an index, or appends to an array with-.remove: removes the value atpath.replace: replaces the existing value atpath.move: removes the value atfromand adds it atpath.copy: copies the value atfromtopath.test: checks that the value atpathequals the suppliedvalue.
JSON Pointer Paths
Patch paths use JSON Pointer syntax:
- The empty pointer
""addresses the whole document. - Non-empty paths use
/-separated reference tokens, such as/metadata/owner. ~1represents/.~0represents~.- Array indexes are decimal strings, such as
/tags/0. - The
addoperation can append to arrays with-, such as/tags/-.
Example escaped paths:
[
{ "op": "replace", "path": "/a~1b", "value": 1 },
{ "op": "replace", "path": "/m~0n", "value": 2 }
]
/a~1b addresses the member named a/b. /m~0n addresses the member named m~n.
Errors
The binding throws JadipaErrorException when the Rust core returns an error. The original error value is available through ex.Error.
Error variants:
JadipaError.InvalidJson: the target JSON could not be parsed.JadipaError.InvalidPatch: the patch document could not be parsed as JSON Patch.JadipaError.PatchApplication: a patch operation failed, for example because a path was missing, an array index was invalid, or atestoperation failed.JadipaError.Serialization: the patched value could not be serialized back to JSON.
try
{
var patchedJson = Jadipa.Jadipa.ApplyPatchJson("""{"name":"old"}""", """
[
{ "op": "replace", "path": "/missing", "value": "new" }
]
""");
}
catch (JadipaErrorException ex) when (ex.Error is JadipaError.PatchApplication)
{
Console.Error.WriteLine(ex.Message);
}
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. 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. |
-
net10.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.