python-fire icon indicating copy to clipboard operation
python-fire copied to clipboard

Parsing of json dumped booleans

Open ramannanda9 opened this issue 4 years ago • 1 comments

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.

ramannanda9 avatar Apr 14 '21 20:04 ramannanda9

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.

kmiller96 avatar Nov 29 '22 05:11 kmiller96