import json def load_inv(inv_str): try: return json.loads(inv_str or "{}") except: return {} def save_inv(inv): return json.dumps(inv)