Skip to content

Instantly share code, notes, and snippets.

@fungusakafungus
Created January 3, 2014 12:31
Show Gist options
  • Save fungusakafungus/8237207 to your computer and use it in GitHub Desktop.
Save fungusakafungus/8237207 to your computer and use it in GitHub Desktop.
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