{"id":25803443,"url":"https://github.com/weichch/system-text-json-jsondiffpatch","last_synced_at":"2025-04-05T21:07:38.166Z","repository":{"id":38215047,"uuid":"426935892","full_name":"weichch/system-text-json-jsondiffpatch","owner":"weichch","description":"High-performance, low-allocating JSON object diff and patch extension for System.Text.Json. Support generating patch document in RFC 6902 JSON Patch format.","archived":false,"fork":false,"pushed_at":"2024-04-22T10:44:00.000Z","size":202,"stargazers_count":95,"open_issues_count":17,"forks_count":12,"subscribers_count":5,"default_branch":"main","last_synced_at":"2024-05-16T10:09:14.427Z","etag":null,"topics":["compare","diff","json","json-diff","json-patch","jsondiffpatch","patch","rfc-6902","system-text-json"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/weichch.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-11-11T09:07:38.000Z","updated_at":"2024-04-27T02:25:38.000Z","dependencies_parsed_at":"2024-01-02T22:38:41.719Z","dependency_job_id":"7fe64c94-0d19-4e50-be6c-0df73b28ae4b","html_url":"https://github.com/weichch/system-text-json-jsondiffpatch","commit_stats":{"total_commits":18,"total_committers":1,"mean_commits":18.0,"dds":0.0,"last_synced_commit":"592940e5a6c7510128b81bb9bedd6cc729805441"},"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/weichch%2Fsystem-text-json-jsondiffpatch","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/weichch%2Fsystem-text-json-jsondiffpatch/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/weichch%2Fsystem-text-json-jsondiffpatch/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/weichch%2Fsystem-text-json-jsondiffpatch/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/weichch","download_url":"https://codeload.github.com/weichch/system-text-json-jsondiffpatch/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247399877,"owners_count":20932876,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["compare","diff","json","json-diff","json-patch","jsondiffpatch","patch","rfc-6902","system-text-json"],"created_at":"2025-02-27T17:54:35.962Z","updated_at":"2025-04-05T21:07:38.144Z","avatar_url":"https://github.com/weichch.png","language":"C#","readme":"# SystemTextJson.JsonDiffPatch\n\n![GitHub](https://img.shields.io/github/license/weichch/system-text-json-jsondiffpatch?color=blueviolet) ![GitHub Workflow Status (branch)](https://img.shields.io/github/actions/workflow/status/weichch/system-text-json-jsondiffpatch/build-and-test.yaml?branch=main) [![JsonDiffPatch](https://img.shields.io/nuget/vpre/SystemTextJson.JsonDiffPatch?style=flat)](https://www.nuget.org/packages/SystemTextJson.JsonDiffPatch/) ![Nuget](https://img.shields.io/nuget/dt/SystemTextJson.JsonDiffPatch?color=important)\n\nHigh-performance, low-allocating JSON object diff and patch extension for System.Text.Json.\n\n## Features\n\n- Compatible with [jsondiffpatch delta format](https://github.com/benjamine/jsondiffpatch/blob/master/docs/deltas.md)\n- Support generating patch document in RFC 6902 JSON Patch format\n- Support .NET and .NET Framework\n- Alternative to [jsondiffpatch.net](https://github.com/wbish/jsondiffpatch.net) which is based on Newtonsoft.Json\n- Fast large JSON document diffing with less memory consumption (see [benchmark](https://github.com/weichch/system-text-json-jsondiffpatch/blob/main/Benchmark.md))\n- Support smart array diffing (e.g. move detect) using LCS (Longest Common Subsequence) and custom array item matcher\n- _(Only when not using RFC 6902 format)_ Support diffing long text using [google-diff-match-patch](http://code.google.com/p/google-diff-match-patch/), or write your own diff algorithm\n- Bonus `DeepEquals` method for comparing `JsonDocument`, `JsonElement` and `JsonNode`\n- Bonus [`JsonValueComparer`](https://github.com/weichch/system-text-json-jsondiffpatch/blob/main/src/SystemTextJson.JsonDiffPatch/JsonValueComparer.cs) that implements semantic comparison of two `JsonValue` objects\n- JSON assert for xUnit, MSTest v2 and NUnit with customizable delta output\n\n## Install\n\n#### JsonDiffPatch\n\n```\nPM\u003e Install-Package SystemTextJson.JsonDiffPatch\n```\n\n#### xUnit Assert\n\n```\nPM\u003e Install-Package SystemTextJson.JsonDiffPatch.Xunit\n```\n\n#### MSTest v2 Assert\n\n```\nPM\u003e Install-Package SystemTextJson.JsonDiffPatch.MSTest\n```\n\n#### NUnit Assert\n\n```\nPM\u003e Install-Package SystemTextJson.JsonDiffPatch.NUnit\n```\n\n## Examples\n\n### Diff\n\n```csharp\n// Diff JsonNode\nvar node1 = JsonNode.Parse(\"{\\\"foo\\\":\\\"bar\\\"}\");\nvar node2 = JsonNode.Parse(\"{\\\"baz\\\":\\\"qux\\\", \\\"foo\\\":\\\"bar\\\"}\");\nvar diff = node1.Diff(node2);\n// Diff with options\nvar diff = node1.Diff(node2, new JsonDiffOptions\n{\n    JsonElementComparison = JsonElementComparison.Semantic\n});\n// Diff and convert delta into RFC 6902 JSON Patch format\nvar diff = node1.Diff(node2, new JsonPatchDeltaFormatter());\n// Diff JSON files\nvar diff = JsonDiffPatcher.DiffFile(file1, file2);\n// Diff Span\u003cbyte\u003e\nvar diff = JsonDiffPatcher.Diff(span1, span2);\n// Diff streams\nvar diff = JsonDiffPatcher.Diff(stream1, stream2);\n// Diff JSON strings\nvar diff = JsonDiffPatcher.Diff(json1, json2);\n// Diff JSON readers\nvar diff = JsonDiffPatcher.Diff(ref reader1, ref reader2);\n```\n\n### Patch \u0026 Unpatch\n\n```csharp\nvar node1 = JsonNode.Parse(\"{\\\"foo\\\":\\\"bar\\\"}\");\nvar node2 = JsonNode.Parse(\"{\\\"baz\\\":\\\"qux\\\", \\\"foo\\\":\\\"bar\\\"}\");\nvar diff = node1.Diff(node2);\n// In-place patch\nJsonDiffPatcher.Patch(ref node1, diff);\n// Clone \u0026 patch\nvar patched = node1.PatchNew(diff);\n// In-place unpatch\nJsonDiffPatcher.ReversePatch(ref node1, diff);\n// Clone \u0026 unpatch\nvar patched = node1.ReversePatchNew(diff);\n```\n\n### DeepEquals\n\n```csharp\n// JsonDocument\nvar doc1 = JsonDocument.Parse(\"{\\\"foo\\\":1}\");\nvar doc2 = JsonDocument.Parse(\"{\\\"foo\\\":1.0}\");\nvar equal = doc1.DeepEquals(doc2);\nvar textEqual = doc1.DeepEquals(doc2, JsonElementComparison.RawText);\nvar semanticEqual = doc1.DeepEquals(doc2, JsonElementComparison.Semantic);\n\n// JsonNode\nvar node1 = JsonNode.Parse(\"{\\\"foo\\\":1}\");\nvar node2 = JsonNode.Parse(\"{\\\"foo\\\":1.0}\");\nvar equal = node1.DeepEquals(node2);\nvar textEqual = node1.DeepEquals(node2, JsonElementComparison.RawText);\nvar semanticEqual = node1.DeepEquals(node2, JsonElementComparison.Semantic);\n```\n\n### Default Options\n\n```csharp\n// Default diff options\nJsonDiffPatcher.DefaultOptions = () =\u003e new JsonDiffOptions\n{\n    JsonElementComparison = JsonElementComparison.Semantic\n};\n\n// Default comparison mode for DeepEquals\nJsonDiffPatcher.DefaultComparison = JsonElementComparison.Semantic;\n```\n\n### Semantic Value Comparison\n```csharp\nvar node1 = JsonNode.Parse(\"\\\"2019-11-27\\\"\");\nvar node2 = JsonNode.Parse(\"\\\"2019-11-27T00:00:00.000\\\"\");\n// dateCompare is 0\nvar dateCompare = JsonValueComparer.Compare(node1, node2);\n\nvar node3 = JsonNode.Parse(\"1\");\nvar node4 = JsonNode.Parse(\"1.00\");\n// numCompare is 0\nvar numCompare = JsonValueComparer.Compare(node3, node4);\n```\n\n### Assert (Unit Testing)\n\n```csharp\nvar expected = JsonNode.Parse(\"{\\\"foo\\\":\\\"bar\\\"}\");\nvar actual = JsonNode.Parse(\"{\\\"baz\\\":\\\"qux\\\", \\\"foo\\\":\\\"bar3\\\"}\");\n\n// xUnit\nJsonAssert.Equal(expected, actual);\nactual.ShouldEqual(expected);\nJsonAssert.NotEqual(expected, actual);\nactual.ShouldNotEqual(expected);\n\n// MSTest\nJsonAssert.AreEqual(expected, actual);\nAssert.That.JsonAreEqual(expected, actual);\nJsonAssert.AreNotEqual(expected, actual);\nAssert.That.JsonAreNotEqual(expected, actual);\n\n// NUnit\nJsonAssert.AreEqual(expected, actual);\nAssert.That(actual, JsonIs.EqualTo(expected));\nJsonAssert.AreNotEqual(expected, actual);\nAssert.That(actual, JsonIs.NotEqualTo(expected));\n```\n\nExample output _(when output is enabled)_:\n```\nJsonAssert.Equal() failure.\nExpected:\n{\n  \"foo\": \"bar\"\n}\nActual:\n{\n  \"baz\": \"qux\",\n  \"foo\": \"bar\"\n}\nDelta:\n{\n  \"foo\": [\n    \"bar\",\n    \"bar3\"\n  ],\n  \"baz\": [\n    \"qux\"\n  ]\n}\n```\n\n## Benchmark\n\nSee detailed [benchmark results](https://github.com/weichch/system-text-json-jsondiffpatch/blob/main/Benchmark.md).\n","funding_links":[],"categories":["Misc","Audio"],"sub_categories":["GUI - other"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fweichch%2Fsystem-text-json-jsondiffpatch","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fweichch%2Fsystem-text-json-jsondiffpatch","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fweichch%2Fsystem-text-json-jsondiffpatch/lists"}