Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Result of comparison depends on the order of datasets being compared #16

Open
fedorov opened this issue Oct 16, 2018 · 1 comment
Open

Comments

@fedorov
Copy link

fedorov commented Oct 16, 2018

This tool does not detect absolute difference between the 2 datasets.

Example:

1s.json:

{
    "Key1": "1"
}

2s.json:

{
    "Key1": "1",
    "Key2": "1"
}
$ python comparejson.py 2s.json 1s.json      
Reason: Length Mismatch: Expected Length: 2, Actual Length: 1
Expected:
  {
      "Key1": "1",
      "Key2": "2"
  }
Actual:
  {
      "Key1": "1"
  }
Missing keys: [u'Key2']
$ python comparejson.py 1s.json 2s.json
$

Is this a bug or an (undocumented) feature?

In comparison, jsondiff detects difference no matter what is the order:

$ jsondiff 1s.json 2s.json                                                                                               
{"Key2": "2"}%
$ jsondiff 2s.json 1s.json                                                                                               
{"$delete": ["Key2"]}%
@fedorov
Copy link
Author

fedorov commented Oct 16, 2018

comparejson.py below:

import json, sys
import jsoncompare
import ast


if len(sys.argv) < 3:
  sys.exit('Error')
json1 = json.loads(open(sys.argv[1],'r').read())
json2 = json.loads(open(sys.argv[2],'r').read())

try:
    ignoredKeys += ast.literal_eval(sys.argv[3])
except IndexError:
    pass

json2 = json.loads(open(sys.argv[2],'r').read())

(check,stack) = jsoncompare.are_same(json1,json2,
                                     ignore_list_order_recursively=False,
                                     ignore_missing_keys=False,
                                     ignore_value_of_keys=ignoredKeys)

if not check:
  print(stack)
  sys.exit(1)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant