Philiprehberger.ConfigDiff
0.3.0
dotnet add package Philiprehberger.ConfigDiff --version 0.3.0
NuGet\Install-Package Philiprehberger.ConfigDiff -Version 0.3.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Philiprehberger.ConfigDiff" Version="0.3.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Philiprehberger.ConfigDiff" Version="0.3.0" />
<PackageReference Include="Philiprehberger.ConfigDiff" />
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Philiprehberger.ConfigDiff --version 0.3.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Philiprehberger.ConfigDiff, 0.3.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Philiprehberger.ConfigDiff@0.3.0
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Philiprehberger.ConfigDiff&version=0.3.0
#tool nuget:?package=Philiprehberger.ConfigDiff&version=0.3.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Philiprehberger.ConfigDiff

Structured diff for JSON configuration files — detect added, removed, changed, and unchanged keys.
Installation
dotnet add package Philiprehberger.ConfigDiff
Usage
using Philiprehberger.ConfigDiff;
var jsonA = """
{
"Logging": { "Level": "Warning" },
"ConnectionStrings": { "Default": "Server=old" },
"FeatureFlag": false
}
""";
var jsonB = """
{
"Logging": { "Level": "Information" },
"ConnectionStrings": { "Default": "Server=old" },
"NewSetting": "hello"
}
""";
ConfigDiffResult diff = ConfigComparer.Compare(jsonA, jsonB);
foreach (var key in diff.Added)
Console.WriteLine($"+ {key}");
foreach (var key in diff.Removed)
Console.WriteLine($"- {key}");
foreach (var change in diff.Changed)
Console.WriteLine($"~ {change.Path}: '{change.OldValue}' -> '{change.NewValue}'");
// Output:
// + NewSetting
// - FeatureFlag
// ~ Logging.Level: 'Warning' -> 'Information'
Compare files
var diff = ConfigComparer.CompareFiles("appsettings.json", "appsettings.Production.json");
Compare streams
using var streamA = File.OpenRead("appsettings.json");
using var streamB = File.OpenRead("appsettings.Production.json");
var diff = ConfigComparer.Compare(streamA, streamB);
Ignore paths
Use ignorePaths to exclude specific keys from the comparison. Supports exact matches and wildcard prefix matches with .*:
var diff = ConfigComparer.Compare(jsonA, jsonB, ignorePaths: new[]
{
"Logging.*", // ignore everything under Logging
"ConnectionStrings.*" // ignore everything under ConnectionStrings
});
// Only NewSetting and FeatureFlag will appear in the result
Rich change entries
Changed entries include both the old and new values via the ConfigChange record:
foreach (var change in diff.Changed)
{
Console.WriteLine($"{change.Path}: {change.OldValue} -> {change.NewValue}");
}
API
ConfigComparer
| Method | Description |
|---|---|
Compare(string jsonA, string jsonB, IEnumerable<string>? ignorePaths = null) |
Diff two JSON strings |
CompareFiles(string pathA, string pathB, IEnumerable<string>? ignorePaths = null) |
Read files from disk and diff them |
Compare(Stream streamA, Stream streamB, IEnumerable<string>? ignorePaths = null) |
Read streams and diff them |
ConfigDiffResult
| Property | Type | Description |
|---|---|---|
Added |
IReadOnlyList<string> |
Keys present in B but not in A |
Removed |
IReadOnlyList<string> |
Keys present in A but not in B |
Changed |
IReadOnlyList<ConfigChange> |
Keys present in both with different values |
Unchanged |
IReadOnlyList<string> |
Keys with identical values |
TotalChanges |
int |
Total count of added + removed + changed entries |
HasDifferences |
bool |
true when any difference exists |
ConfigChange
| Property | Type | Description |
|---|---|---|
Path |
string |
Dot-notation key path |
OldValue |
string? |
Value in A |
NewValue |
string? |
Value in B |
Development
dotnet build src/Philiprehberger.ConfigDiff.csproj --configuration Release
Support
If you find this project useful:
License
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. 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. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net8.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.