Yo, json.dump can be finicky with complex data! Nested dicts? Lists? No prob—as long as everything’s JSON-serializable. But if you’ve got custom objects or weird types, it’ll choke.
Try this: run `json.dumps(data)` before dumping to a file. If it errors, you’ll know *exactly* what’s breaking it. For cleaning, `str()` or custom encoders (look up `json.JSONEncoder`) can save you.
Also, yeah, close the file or use `with`—it’s cleaner.
Try this: run `json.dumps(data)` before dumping to a file. If it errors, you’ll know *exactly* what’s breaking it. For cleaning, `str()` or custom encoders (look up `json.JSONEncoder`) can save you.
Also, yeah, close the file or use `with`—it’s cleaner.
