Skip to content
Snippets Groups Projects
Commit 1b121ea4 authored by Chris Lamb's avatar Chris Lamb :eyes:
Browse files

Optionally compare JSON files using Python jsondiff module. (Closes: #888112)

parent de1abeae
No related branches found
No related tags found
No related merge requests found
......@@ -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>,
......
......@@ -64,6 +64,7 @@ override_dh_python3:
--recommends=binwalk \
--recommends=defusedxml \
--recommends=guestfs \
--recommends=jsondiff \
--recommends=progressbar \
--recommends=python-debian \
--recommends=rpm-python \
......
......@@ -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(
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment