Skip to content

Instantly share code, notes, and snippets.

@gary-liguoliang
Last active November 19, 2019 10:13
Show Gist options
  • Save gary-liguoliang/2179c482df330b9609f3731e9be70f46 to your computer and use it in GitHub Desktop.
Save gary-liguoliang/2179c482df330b9609f3731e9be70f46 to your computer and use it in GitHub Desktop.
if expected != actual:
import json
with open("expected.json", "w+") as e:
e.write(json.dumps(expected, indent=4, sort_keys=True))
with open("actual.json", "w+") as a:
a.write(json.dumps(actual, indent=4, sort_keys=True))
@gary-liguoliang
Copy link
Author

with open('expected.json') as expected, open('actual.json') as actual:
    expected = sorted(json.load(expected)['results'], key=lambda k: k['user_id'])
    actual = sorted(json.load(actual)['results'], key=lambda k: k['user_id'])

    with open("expected-r.json", "w+") as e:
        e.write(json.dumps(expected, indent=4, sort_keys=True))
    with open("actual-r.json", "w+") as a:
        a.write(json.dumps(actual, indent=4, sort_keys=True))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment