├── .github
├── CODEOWNERS
└── workflows
│ └── build-and-test.yaml
├── icon.png
├── src
├── SystemTextJson.JsonDiffPatch
│ ├── JsonStringValueKind.cs
│ ├── Properties
│ │ ├── AssemblyInfo.cs
│ │ └── IsExternalInit.cs
│ ├── Diffs
│ │ ├── ArrayItemMatch.cs
│ │ ├── TextMatch.cs
│ │ ├── Formatters
│ │ │ ├── IJsonDiffDeltaFormatter.cs
│ │ │ ├── DefaultDeltaFormatter.cs
│ │ │ └── JsonPatchDeltaFormatter.cs
│ │ ├── JsonDiffContext.cs
│ │ ├── ArrayItemMatchContext.cs
│ │ ├── JsonDiffPatcher.Object.cs
│ │ ├── JsonDiffOptions.cs
│ │ ├── JsonDiffPatcher.Text.cs
│ │ └── Lcs.cs
│ ├── Patching
│ │ ├── TextPatch.cs
│ │ ├── JsonPatchOptions.cs
│ │ ├── JsonReversePatchOptions.cs
│ │ ├── JsonDiffPatcher.Text.cs
│ │ ├── JsonDiffPatcher.Array.cs
│ │ ├── JsonDiffPatcher.Object.cs
│ │ └── JsonDiffPatcher.Patch.cs
│ ├── JsonElementComparison.cs
│ ├── JsonDiffPatcher.cs
│ ├── JsonComparerOptions.cs
│ ├── JsonValueComparer.String.cs
│ ├── JsonValueComparer.Number.cs
│ ├── SystemTextJson.JsonDiffPatch.csproj
│ ├── JsonValueComparer.cs
│ ├── JsonBytes.cs
│ └── JsonValueWrapper.cs
├── SystemTextJson.JsonDiffPatch.NUnit
│ ├── JsonEqualConstraint.cs
│ ├── JsonNotEqualConstraint.cs
│ ├── SystemTextJson.JsonDiffPatch.NUnit.csproj
│ ├── JsonDiffConstraintResult.cs
│ ├── JsonIs.cs
│ └── JsonDiffConstraint.cs
├── SystemTextJson.JsonDiffPatch.Xunit
│ ├── JsonNotEqualException.cs
│ ├── JsonEqualException.cs
│ └── SystemTextJson.JsonDiffPatch.Xunit.csproj
├── SystemTextJson.JsonDiffPatch.MSTest
│ └── SystemTextJson.JsonDiffPatch.MSTest.csproj
├── Directory.Build.props
└── SystemTextJson.JsonDiffPatch.sln
├── test
├── Directory.Build.props
├── SystemTextJson.JsonDiffPatch.UnitTests
│ ├── DocumentTests
│ │ ├── DocumentTestData.cs
│ │ └── DeepEqualsTests.cs
│ ├── ElementTests
│ │ ├── ElementTestData.cs
│ │ └── DeepEqualsTests.cs
│ ├── DefaultOptionsTests.cs
│ ├── SystemTextJson.JsonDiffPatch.UnitTests.csproj
│ ├── NodeTests
│ │ ├── JsonValueComparerTests.cs
│ │ ├── ObjectDeepEqualsTests.cs
│ │ ├── PatchTests.cs
│ │ ├── DiffTests.cs
│ │ └── ElementDeepEqualsTests.cs
│ ├── DeepEqualsTestData.cs
│ ├── DemoFileTests.cs
│ └── FormatterTests
│ │ └── JsonPatchDeltaFormatterTests.cs
├── SystemTextJson.JsonDiffPatch.NUnit.Tests
│ ├── SystemTextJson.JsonDiffPatch.NUnit.Tests.csproj
│ └── JsonAssertTests.cs
├── SystemTextJson.JsonDiffPatch.MSTest.Tests
│ ├── SystemTextJson.JsonDiffPatch.MSTest.Tests.csproj
│ └── JsonAssertTests.cs
├── SystemTextJson.JsonDiffPatch.Benchmark
│ ├── PatchJsonFileBenchmark.cs
│ ├── QuickDiff.cs
│ ├── OptionsJsonFileBenchmark.cs
│ ├── BasicBenchmark.cs
│ ├── JsonFileBenchmark.cs
│ ├── DeepEqualsJsonFileBenchmark.cs
│ ├── Program.cs
│ ├── BenchmarkHelper.cs
│ ├── QuickDeepEquals.cs
│ ├── DiffJsonFileBenchmark.cs
│ ├── SystemTextJson.JsonDiffPatch.Benchmark.csproj
│ └── JsonHelper.cs
├── SystemTextJson.JsonDiffPatch.Xunit.Tests
│ ├── SystemTextJson.JsonDiffPatch.Xunit.Tests.csproj
│ └── JsonAssertTests.cs
└── Examples
│ ├── demo_diff.json
│ ├── demo_diff_jsonpatch.json
│ ├── demo_right.json
│ ├── demo_left.json
│ └── demo_diff_notext.json
├── LICENSE
├── ReleaseNotes.md
├── Benchmark.md
├── README.md
└── .gitignore
/.github/CODEOWNERS:
--------------------------------------------------------------------------------
1 | * @weichch
--------------------------------------------------------------------------------
/icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/weichch/system-text-json-jsondiffpatch/HEAD/icon.png
--------------------------------------------------------------------------------
/src/SystemTextJson.JsonDiffPatch/JsonStringValueKind.cs:
--------------------------------------------------------------------------------
1 | namespace System.Text.Json.JsonDiffPatch
2 | {
3 | internal enum JsonStringValueKind
4 | {
5 | String,
6 | DateTime,
7 | Guid
8 | }
9 | }
--------------------------------------------------------------------------------
/src/SystemTextJson.JsonDiffPatch/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Runtime.CompilerServices;
2 |
3 | [assembly:InternalsVisibleTo("SystemTextJson.JsonDiffPatch.Benchmark")]
4 | [assembly:InternalsVisibleTo("SystemTextJson.JsonDiffPatch.UnitTests")]
5 |
--------------------------------------------------------------------------------
/test/Directory.Build.props:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | net8.0;net7.0;net6.0;net48
5 |
6 |
7 |
8 | false
9 | enable
10 | latest
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/src/SystemTextJson.JsonDiffPatch/Diffs/ArrayItemMatch.cs:
--------------------------------------------------------------------------------
1 | namespace System.Text.Json.JsonDiffPatch.Diffs
2 | {
3 | ///
4 | /// Defines a function that determines whether two items in arrays are equal.
5 | ///
6 | /// The comparison context.
7 | public delegate bool ArrayItemMatch(ref ArrayItemMatchContext context);
8 | }
9 |
--------------------------------------------------------------------------------
/src/SystemTextJson.JsonDiffPatch/Diffs/TextMatch.cs:
--------------------------------------------------------------------------------
1 | namespace System.Text.Json.JsonDiffPatch.Diffs
2 | {
3 | ///
4 | /// Defines a function that diffs two long texts.
5 | ///
6 | /// The left string.
7 | /// The right string.
8 | public delegate string? TextMatch(string str1, string str2);
9 | }
10 |
--------------------------------------------------------------------------------
/src/SystemTextJson.JsonDiffPatch/Patching/TextPatch.cs:
--------------------------------------------------------------------------------
1 | namespace System.Text.Json.JsonDiffPatch.Patching
2 | {
3 | ///
4 | /// Defines a function that diffs two long texts.
5 | ///
6 | /// The left string.
7 | /// The right string.
8 | public delegate string TextPatch(string str1, string str2);
9 | }
10 |
--------------------------------------------------------------------------------
/src/SystemTextJson.JsonDiffPatch.NUnit/JsonEqualConstraint.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Nodes;
2 |
3 | namespace System.Text.Json.JsonDiffPatch.Nunit
4 | {
5 | class JsonEqualConstraint : JsonDiffConstraint
6 | {
7 | public JsonEqualConstraint(JsonNode? expected)
8 | : base(expected)
9 | {
10 | }
11 |
12 | protected override bool Test() => Delta is null;
13 | }
14 | }
--------------------------------------------------------------------------------
/src/SystemTextJson.JsonDiffPatch/Properties/IsExternalInit.cs:
--------------------------------------------------------------------------------
1 | // https://stackoverflow.com/questions/64749385/predefined-type-system-runtime-compilerservices-isexternalinit-is-not-defined
2 | // https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/preprocessor-directives
3 | #if !NET
4 | namespace System.Runtime.CompilerServices
5 | {
6 | internal static class IsExternalInit
7 | {
8 | }
9 | }
10 | #endif
--------------------------------------------------------------------------------
/src/SystemTextJson.JsonDiffPatch.Xunit/JsonNotEqualException.cs:
--------------------------------------------------------------------------------
1 | using Xunit.Sdk;
2 |
3 | namespace System.Text.Json.JsonDiffPatch.Xunit
4 | {
5 | ///
6 | /// Exception thrown when two JSON objects are unexpectedly equal.
7 | ///
8 | public class JsonNotEqualException : XunitException
9 | {
10 | public JsonNotEqualException()
11 | : base("JsonAssert.NotEqual() failure.")
12 | {
13 | }
14 | }
15 | }
--------------------------------------------------------------------------------
/src/SystemTextJson.JsonDiffPatch.NUnit/JsonNotEqualConstraint.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Nodes;
2 |
3 | namespace System.Text.Json.JsonDiffPatch.Nunit
4 | {
5 | class JsonNotEqualConstraint : JsonDiffConstraint
6 | {
7 | public JsonNotEqualConstraint(JsonNode? expected)
8 | : base(expected)
9 | {
10 | }
11 |
12 | public override Func? OutputFormatter => null;
13 | protected override bool Test() => Delta is not null;
14 | }
15 | }
--------------------------------------------------------------------------------
/src/SystemTextJson.JsonDiffPatch/Patching/JsonPatchOptions.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.JsonDiffPatch.Patching;
2 |
3 | namespace System.Text.Json.JsonDiffPatch
4 | {
5 | ///
6 | /// Represents options for patching JSON object.
7 | ///
8 | public struct JsonPatchOptions
9 | {
10 | ///
11 | /// Gets or sets the function to patch long text.
12 | ///
13 | public TextPatch? TextPatchProvider { get; set; }
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/src/SystemTextJson.JsonDiffPatch/Patching/JsonReversePatchOptions.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.JsonDiffPatch.Patching;
2 |
3 | namespace System.Text.Json.JsonDiffPatch
4 | {
5 | ///
6 | /// Represents options for patching JSON object.
7 | ///
8 | public struct JsonReversePatchOptions
9 | {
10 | ///
11 | /// Gets or sets the function to reverse long text patch.
12 | ///
13 | public TextPatch? ReverseTextPatchProvider { get; set; }
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/src/SystemTextJson.JsonDiffPatch.Xunit/JsonEqualException.cs:
--------------------------------------------------------------------------------
1 | using Xunit.Sdk;
2 |
3 | namespace System.Text.Json.JsonDiffPatch.Xunit
4 | {
5 | ///
6 | /// Exception thrown when two JSON objects are unexpectedly not equal.
7 | ///
8 | public class JsonEqualException : XunitException
9 | {
10 | public JsonEqualException()
11 | : base("JsonAssert.Equal() failure.")
12 | {
13 | }
14 |
15 | public JsonEqualException(string output)
16 | : base($"JsonAssert.Equal() failure.{Environment.NewLine}{output}")
17 | {
18 | }
19 | }
20 | }
--------------------------------------------------------------------------------
/test/SystemTextJson.JsonDiffPatch.UnitTests/DocumentTests/DocumentTestData.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.Text.Json;
3 |
4 | namespace SystemTextJson.JsonDiffPatch.UnitTests.DocumentTests
5 | {
6 | public class DocumentTestData
7 | {
8 | public static IEnumerable