Skip to content

Instantly share code, notes, and snippets.

@rosemichaele
Last active September 7, 2017 18:25
Show Gist options
  • Save rosemichaele/1f4026891230d9626f3ea04c1ea2334f to your computer and use it in GitHub Desktop.
Save rosemichaele/1f4026891230d9626f3ea04c1ea2334f to your computer and use it in GitHub Desktop.
Remove and return field values in JSON formatted text.
import json
from collections import OrderedDict
def replace_values(d):
for k in d:
if isinstance(d[k], dict):
d[k] = replace_values(d[k])
elif isinstance(d[k], float):
d[k] = int()
else:
d[k] = type(d[k])()
return d
def buildCommand(jsonFile):
""":param: jsonFile -> str: a string value containing JSON formatted text"""
d = json.loads(jsonFile, object_pairs_hook=OrderedDict)
res = replace_values(d)
return json.dumps(res)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment