import json with open("jsontest", "w", encoding="utf-8") as f: f.write(json.dumps(['foo', {'bar': ('baz', None, 1.0, 2)}]))