Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Branch: master
Fetching contributors…

Cannot retrieve contributors at this time

28 lines (25 sloc) 1.122 kB
"""
@author: Jonathan Mickle
@summary: Traverses a through multi level dictionaries to diff them and return the changes -- Thanks to @tobywolf <https://github.com/tobywolf> for correcting logic
@param original: takes in the original unmodified JSON
@param modified: Takes in the modified json file for comparison
@return: a json dictionary of changes key-> value
"""
def diffDict(original, modified):
if isinstance(original, dict) and isinstance(modified, dict):
changes = {}
for key, value in modified.iteritems():
if isinstance(value, dict):
innerDict = diffDict(original[key], modified[key])
if innerDict != {}:
changes[key] = {}
changes[key].update(innerDict)
else:
if original.has_key(key):
if value != original[key]:
changes[key] = value
else:
changes[key] = value
return changes
else:
raise Exception('parameters must be a dictionary')
Jump to Line
Something went wrong with that request. Please try again.