gojsondiff

repository·master·Indexed 20 days ago

https://github.com/yudai/gojsondiff

A 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.

Tokens
666
Snippets
7
Records
7
Agent score
19%

What's inside gojsondiff

  1. Use the `jd` CLI tool to diff JSON files

    master

    The 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.json
  2. Configure the jd CLI flags

    master

    The jd CLI provides several flags to control the output format and appearance:

    FlagShortEnv VarDescription
    --format-fDIFF_FORMATDiff Output Format (ascii or delta). Default is ascii.
    --coloring-cCOLORINGEnable coloring in ascii mode. (Not available in delta mode).
    --quiet-qQUIETSuppress 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.json
    jd --format ascii --coloring file1.json file2.json
  3. Use the jd CLI tool to apply a JSON patch

    master

    The 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.json
  4. Use the jd CLI to compare two JSON files

    master

    The 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