SpecWorks.JsonDiff.Cli 1.0.0

dotnet tool install --global SpecWorks.JsonDiff.Cli --version 1.0.0
                    
This package contains a .NET tool you can call from the shell/command line.
dotnet new tool-manifest
                    
if you are setting up this repo
dotnet tool install --local SpecWorks.JsonDiff.Cli --version 1.0.0
                    
This package contains a .NET tool you can call from the shell/command line.
#tool dotnet:?package=SpecWorks.JsonDiff.Cli&version=1.0.0
                    
nuke :add-package SpecWorks.JsonDiff.Cli --version 1.0.0
                    

JSON Diff CLI

Command-line tool for generating RFC 6902 JSON Patch documents by comparing two JSON files.

Installation

Install from NuGet:

dotnet tool install --global SpecWorks.JsonDiff.Cli

Update to the latest version:

dotnet tool update --global SpecWorks.JsonDiff.Cli

Uninstall:

dotnet tool uninstall --global SpecWorks.JsonDiff.Cli

From Source

Build and pack locally:

cd src/SpecWorks.JsonDiff.Cli
dotnet pack
dotnet tool install --global --add-source ./bin/Debug SpecWorks.JsonDiff.Cli

Usage

jsondiff <source-file> <target-file> [options]

Arguments

  • <source-file> - Path to the source JSON file
  • <target-file> - Path to the target JSON file

Options

  • --pretty - Format output with indentation
  • --help - Show help message

Examples

Compare two JSON files:

dotnet run -- source.json target.json

Compare with pretty-printed output:

dotnet run -- source.json target.json --pretty

Pipe output to a file:

dotnet run -- old.json new.json --pretty > patch.json

Output

The tool outputs a JSON Patch document (RFC 6902) to stdout. The patch represents the operations needed to transform the source JSON into the target JSON.

Example output:

[
  { "op": "replace", "path": "/age", "value": 31 },
  { "op": "remove", "path": "/city" },
  { "op": "add", "path": "/country", "value": "USA" }
]

Exit Codes

  • 0 - Success
  • 1 - Invalid arguments or file not found
  • 2 - Invalid JSON in input files
  • 3 - Error generating diff

RFC 6902 Compliance

This tool generates JSON Patch documents that strictly comply with RFC 6902. It supports all six operation types:

  • add - Add a value
  • remove - Remove a value
  • replace - Replace a value
  • move - Move a value
  • copy - Copy a value
  • test - Test that a value equals specified

Examples

Basic Usage

# Compare two files
dotnet run -- before.json after.json

# Pretty-printed output
dotnet run -- before.json after.json --pretty

Real-World Scenarios

# Generate patch for configuration changes
dotnet run -- config-v1.json config-v2.json --pretty > config.patch

# Compare API responses
dotnet run -- response-old.json response-new.json

# Version control integration
dotnet run -- committed.json working.json --pretty

Integration with Other Tools

The output can be used with any RFC 6902 compliant JSON Patch implementation:

# Generate patch
dotnet run -- old.json new.json > changes.patch

# Apply patch using another tool
json-patch apply old.json changes.patch > result.json

This CLI tool uses the SpecWorks.JsonDiff library, which is part of the SpecWorks collection of specification-based software components.

License

MIT License - See LICENSE file for details.

Product Compatible and additional computed target framework versions.
.NET net9.0 is compatible.  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.

This package has no dependencies.

Version Downloads Last Updated
1.0.0 148 1/9/2026

Initial release (v1.0) - CLI tool for RFC 6902 JSON Patch generation.