python - Writing to JSON produces TypeError: dump() takes at least 2 arguments (1 given) -
i trying load in json file. update , write back. here attempt @ getting error:
typeerror: dump() takes @ least 2 arguments (1 given)
with open('employees.json') data_file: employees = json.load(data_file) data_file.close employees['employees'].append({ "id": "2", "name": "rob croft", "key": "0003837852"}) open('employees.json', 'w') data_file: json.dump(employees) data_file.close
you forgot pass in file object:
json.dump(employees, data_file)
since using file object context manager with
statement, not need manually close file. , using data_file.close
entirely redundant since not calling file.close()
method.
Comments
Post a Comment