[diffoscope] 01/01: Optionally compare JSON files using Python jsondiff module. (Closes: #888112)
Chris Lamb
chris at chris-lamb.co.uk
Thu Jan 25 02:14:50 CET 2018
This is an automated email from the git hooks/post-receive script.
lamby pushed a commit to branch master
in repository diffoscope.
commit 1b121ea4efdb9fc614d32172b9749b5dd4afc550
Author: Chris Lamb <lamby at debian.org>
Date: Thu Jan 25 12:14:03 2018 +1100
Optionally compare JSON files using Python jsondiff module. (Closes: #888112)
---
debian/control | 1 +
debian/rules | 1 +
diffoscope/comparators/json.py | 18 ++++++++++++++++++
3 files changed, 20 insertions(+)
diff --git a/debian/control b/debian/control
index 538a2d9..ead888b 100644
--- a/debian/control
+++ b/debian/control
@@ -52,6 +52,7 @@ Build-Depends:
python3-distro <!nocheck>,
python3-docutils,
python3-guestfs <!nocheck>,
+ python3-jsondiff <!nocheck>,
python3-libarchive-c,
python3-magic,
python3-progressbar <!nocheck>,
diff --git a/debian/rules b/debian/rules
index 2aae24d..cffaf02 100755
--- a/debian/rules
+++ b/debian/rules
@@ -64,6 +64,7 @@ override_dh_python3:
--recommends=binwalk \
--recommends=defusedxml \
--recommends=guestfs \
+ --recommends=jsondiff \
--recommends=progressbar \
--recommends=python-debian \
--recommends=rpm-python \
diff --git a/diffoscope/comparators/json.py b/diffoscope/comparators/json.py
index 5baef34..06da4ed 100644
--- a/diffoscope/comparators/json.py
+++ b/diffoscope/comparators/json.py
@@ -24,6 +24,11 @@ from diffoscope.difference import Difference
from .utils.file import File
+try:
+ import jsondiff
+except ImportError: # noqa
+ jsondiff = None
+
class JSONFile(File):
@classmethod
@@ -59,6 +64,19 @@ class JSONFile(File):
)
if difference:
+ if jsondiff is not None:
+ a = getattr(self, 'parsed', {})
+ b = getattr(other, 'parsed', {})
+
+ diff = {repr(x): y for x, y in jsondiff.diff(a, b).items()}
+
+ difference.add_comment("Similarity: {}%".format(
+ jsondiff.similarity(a, b),
+ ))
+ difference.add_comment("Differences: {}".format(
+ json.dumps(diff, indent=2, sort_keys=True),
+ ))
+
return [difference]
difference = Difference.from_text(
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/reproducible/diffoscope.git
More information about the diffoscope
mailing list