Error when diffing json files
When using diffoscope on certain JSON files, the dump of the diff seems to fail. I have found 2 examples of this issue, with different exceptions being raised
I first ran diffoscope using diffoscope file1.json file2.json
.
Here's the content of the files:
{"first": {"second": ["third"]}}
{"first": {"second": ["third", "fourth"]}}
And here's the error's traceback:
Traceback (most recent call last):
File "diffoscope/main.py", line 745, in main
sys.exit(run_diffoscope(parsed_args))
File "diffoscope/main.py", line 697, in run_diffoscope
difference = compare_root_paths(path1, path2)
File "diffoscope/comparators/utils/compare.py", line 74, in compare_root_paths
difference = compare_files(file1, file2)
File "diffoscope/comparators/utils/compare.py", line 128, in compare_files
return file1.compare(file2, source)
File "diffoscope/comparators/utils/file.py", line 464, in compare
difference = self._compare_using_details(other, source)
File "diffoscope/comparators/utils/file.py", line 382, in _compare_using_details
details.extend(self.compare_details(other, source))
File "diffoscope/comparators/json.py", line 59, in compare_details
self.compare_with_jsondiff(difference, other)
File "diffoscope/comparators/json.py", line 91, in compare_with_jsondiff
json.dumps(diff, indent=2, sort_keys=True)
File "/usr/lib/python3.8/json/__init__.py", line 234, in dumps
return cls(
File "/usr/lib/python3.8/json/encoder.py", line 201, in encode
chunks = list(chunks)
File "/usr/lib/python3.8/json/encoder.py", line 431, in _iterencode
yield from _iterencode_dict(o, _current_indent_level)
File "/usr/lib/python3.8/json/encoder.py", line 405, in _iterencode_dict
yield from chunks
File "/usr/lib/python3.8/json/encoder.py", line 405, in _iterencode_dict
yield from chunks
File "/usr/lib/python3.8/json/encoder.py", line 376, in _iterencode_dict
raise TypeError(f'keys must be str, int, float, bool or None, '
TypeError: keys must be str, int, float, bool or None, not Symbol
Here's the second error I found, when running diffoscope lang1.json lang2.json
:
Traceback (most recent call last):
File "diffoscope/main.py", line 745, in main
sys.exit(run_diffoscope(parsed_args))
File "diffoscope/main.py", line 697, in run_diffoscope
difference = compare_root_paths(path1, path2)
File "diffoscope/comparators/utils/compare.py", line 74, in compare_root_paths
difference = compare_files(file1, file2)
File "diffoscope/comparators/utils/compare.py", line 128, in compare_files
return file1.compare(file2, source)
File "comparators/utils/file.py", line 464, in compare
difference = self._compare_using_details(other, source)
File "diffoscope/comparators/utils/file.py", line 382, in _compare_using_details
details.extend(self.compare_details(other, source))
File "diffoscope/comparators/json.py", line 59, in compare_details
self.compare_with_jsondiff(difference, other)
File "diffoscope/comparators/json.py", line 91, in compare_with_jsondiff
json.dumps(diff, indent=2, sort_keys=True)
File "/usr/lib/python3.8/json/__init__.py", line 234, in dumps
return cls(
File "/usr/lib/python3.8/json/encoder.py", line 201, in encode
chunks = list(chunks)
File "/usr/lib/python3.8/json/encoder.py", line 431, in _iterencode
yield from _iterencode_dict(o, _current_indent_level)
File "/usr/lib/python3.8/json/encoder.py", line 405, in _iterencode_dict
yield from chunks
File "/usr/lib/python3.8/json/encoder.py", line 405, in _iterencode_dict
yield from chunks
File "/usr/lib/python3.8/json/encoder.py", line 353, in _iterencode_dict
items = sorted(dct.items())
TypeError: '<' not supported between instances of 'Symbol' and 'Symbol'
I have also attached both files for convenience: