Created
March 10, 2023 09:46
-
-
Save cabo/dafd9a841747de643c1daf04ca47494f to your computer and use it in GitHub Desktop.
Diff two JSON files after normalizing them with jq
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'open3' | |
require 'tempfile' | |
require 'shellwords' | |
if ARGV.size != 2 | |
warn "** usage: jsondiff.rb j1 j2" | |
exit 63 | |
end | |
files = ARGV.dup.map do |arg| | |
ARGV.replace([arg]) | |
f = ARGF.read | |
result, err, _s = Open3.capture3("jq", stdin_data: f) | |
warn err | |
file = Tempfile.new("jsondiff-") | |
file.write(result) | |
file.close | |
file.path | |
end | |
exec("diff -u #{files.shelljoin}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment