Here is how I dump a file
with open(\'es_hosts.json\', \'w\') as fp:
json.dump(\',\'.join(host_list.keys()), fp)
The results is
Well, that's not valid json, so the json
module won't help you to write that data. But you can do this:
import json
with open('es_hosts.json', 'w') as fp:
data = ['a', 'b', 'c']
fp.write(json.dumps(','.join(data)).replace('"', ''))
That's because you asked for json
, but since that's not json, this should suffice:
with open('es_hosts.json', 'w') as fp:
data = ['a', 'b', 'c']
fp.write(','.join(data))