`json.dump(data, f)` would be the more straightforward way to get this done.