python-fire
python-fire copied to clipboard
Parsing of json dumped booleans
Currently, fire command does not recognize json dumped booleans i.e. [true/false] and converts them to strings. Is there a workaround for this atm.
Had this exact same issue. Not a perfect solution by any means, but what I do is convert those stringified values after the fact using a recursive function.
def correct_json_decoding(obj):
if isinstance(obj, list):
return [correct_json_decoding(x) for x in obj]
elif isinstance(obj, dict):
return {correct_json_decoding(k): correct_json_decoding(v) for k, v in obj.items()}
else:
if obj == "true":
return True
elif obj == "false":
return False
else:
return obj
Leaving this here in case someone else has the same issue.