Install gojsondiff as a Go library
masterTo use gojsondiff within your Go projects, install the package using go get.
go get github.com/yudai/gojsondiffrepository·master·Indexed 20 days ago
https://github.com/yudai/gojsondiffA Go library and CLI tool for calculating differences between two JSON structures and applying those differences as patches. Includes the jd CLI for generating human-readable or delta-format diffs and the jp CLI for applying delta-format patches to JSON files.
To use gojsondiff within your Go projects, install the package using go get.
go get github.com/yudai/gojsondiffThe repository includes a CLI tool package. You can install it by running go get on the jd subpackage.
go get github.com/yudai/gojsondiff/jdThe jd command compares two JSON files. By default, it produces a human-readable diff output.
To use the jsondiffpatch compatible delta format instead, use the -f delta flag.
# Standard diff output
jd one.json another.json
# Delta format output
jd -f delta one.json another.jsonThe jp command applies a diff file (in the delta format) to a target JSON file.
jp diff.delta one.jsonThe jd CLI provides several flags to control the output format and appearance:
| Flag | Short | Env Var | Description |
|---|---|---|---|
--format | -f | DIFF_FORMAT | Diff Output Format (ascii or delta). Default is ascii. |
--coloring | -c | COLORING | Enable coloring in ascii mode. (Not available in delta mode). |
--quiet | -q | QUIET | Suppress output if no differences are found. |
Example with flags:
# Compare files using delta format without coloring
jd -f delta file1.json file2.json
# Compare files using ascii format with coloring enabled
jd -f ascii -c file1.json file2.jsonjd --format ascii --coloring file1.json file2.jsonThe jd CLI tool allows you to apply a JSON patch (in a specific diff format) to a target JSON file. It reads a diff file and a JSON file from the command line arguments and outputs the resulting JSON after the patch has been applied to stdout.
Usage:
jd <diff_file> <json_file>
Exit Codes:
1: Not enough arguments provided.2: Failed to open a file or failed to load the diff file.jd diff.json target.jsonThe jd CLI tool generates a human-readable diff between two JSON files. It supports two output formats: ascii (visual representation of the JSON structure) and delta (a list of changes).
Basic Usage:
jd <json_file_1> <json_file_2>Exit Codes:
1: Differences were found.2: Failed to open a file.3: Failed to unmarshal JSON.4: Unknown format specified.jd file1.json file2.json