~mcepl/json_diff#11: 
JSON is not required to be a dictionary

As far as I can tell, all the test files use dictionaries as the top-level object. But JSON does not require this, and when I tried running it on a pair of files containing arrays, it crashed.

According to the spec, json is made up of one element, and an element is made up of a value optionally surrounded by whitespace. A value is any of object, array, string, number, "true", "false", "null".

Status
REPORTED
Submitter
~mcepl
Assigned to
No-one
Submitted
9 months ago
Updated
9 months ago
Labels
No labels applied.

~mcepl 9 months ago

Give me the example test data failing, please.

~mcepl 9 months ago

Hmm, well, it's been ages since I filed this, but you can just generate one:

$ ipython3
In [1]: import json

In [2]: with open('old.json', 'w') as f: json.dump([1, 2, 3], f)                                                                                      

In [3]: with open('new.json', 'w') as f: json.dump([1, 3, 3], f)
$ json_diff old.json new.json
Traceback (most recent call last):
  File ".../bin/json_diff", line 10, in <module>
    sys.exit(main())
  File ".../python3.7/site-packages/json_diff.py", line 370, in main
    diff_res = diff.compare_dicts()
  File ".../python3.7/site-packages/json_diff.py", line 305, in compare_dicts
    old_keys = set(old_obj.keys())
AttributeError: 'list' object has no attribute 'keys'

~mcepl 9 months ago

Same thing - this prevents me from using json-diff with the json I have.

Register here or Log in to comment, or comment via email.