"""JSON Utility Functions.""" # flake8: noqa: A005 from datetime import date from decimal import Decimal def convert_data(data): """Convert data objects that are not natively convertible to JSON. Any data type that is not handled with this is passed through. The JSON operation should handle it like any other un-serializable data type. Args: data (Any): non JSON serializable data object. Returns: str, float, bool: appropriate serialized data. """ if isinstance(data, Decimal): return float(data) if isinstance(data, date): return data.isoformat() return data