simonw / csv-diff

Python CLI tool and library for diffing CSV and JSON files
Apache License 2.0
292 stars 47 forks source link

Support JSON inputs too #12

Closed simonw closed 3 years ago

simonw commented 3 years ago

I find myself wanting to generate commit messages for JSON files.

This can reuse almost all of the logic from csv-diff - so for the moment I'm going to add that ability here rather than spin up a brand new tool.

A rename if this tool can come later!

simonw commented 3 years ago

Annoyingly the --json flag is already being used for "output as JSON".

simonw commented 3 years ago

I can use --format=json instead (already has --format=csv and --format=tsv).

simonw commented 3 years ago

Had to add special treatment for nested lists and objects - they get serialized to a JSON string and compared that way.

Example output:

% csv-diff locations.json locations-updated.json --format json --key id       
3 rows changed

  id: rec00SICtL8KJiLim
    Appointment scheduling instructions: "["https://www.riteaid.com/pharmacy/covid-qualifier"]" => "["https://www.riteaid.com/pharmacy/covid-qualifier", "blah 2"]"

  id: rec05xrPZ4b7dCDns
    Location Type: "Pharmacy" => "Pharmacy 2"

  id: rec0IOCI2WsksvXef
    Name: "WALMART PHARMACY 10-3477" => "WALMART PHARMACY 10-347"