def handle_nan(value):
    """Remove nan values that can't be json encoded"""
    if isinstance(value, float):
        if value == float('inf'):
            return '<inf>'
        if value == float('-inf'):
            return '<-inf>'
        if value != value:
            return '<nan>'
    return value
