Created
January 3, 2014 12:31
-
-
Save fungusakafungus/8237207 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def process_dict_item(k, v): | |
try: | |
return k, int(v) | |
except (TypeError, ValueError): | |
if k == 'EbsOptimized' and v == 'true': | |
return 'EbsOptimized', 1 | |
if k == 'NoEcho' and v == 'true': | |
return 'NoEcho', 1 | |
return k, replace_quoted_ints_in_values(v) | |
def replace_quoted_ints_in_values(o): | |
if isinstance(o, dict): | |
return dict(process_dict_item(k, v) for k,v in o.items()) | |
elif isinstance(o, list): | |
return list(replace_quoted_ints_in_values(l) for l in o) | |
else: | |
return o | |
def normalize_file(f, replace_ints=True): | |
j = json.load(f) | |
if replace_ints: | |
j = replace_quoted_ints_in_values(j) | |
return json.dumps(j, indent=2, sort_keys=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment