import json def is_json_serializable(x): try: json.dumps(x) return True except TypeError: return False