Last active
September 7, 2017 18:25
-
-
Save rosemichaele/1f4026891230d9626f3ea04c1ea2334f to your computer and use it in GitHub Desktop.
Remove and return field values in JSON formatted text.
This file contains hidden or 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
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