-1

How to add list values into a JSON file. Here is my code :

import os,string
drives_a = [chr(x) + ':' for x in range(65, 90) if os.path.exists(chr(x) + ':')]
Arkistarvh Kltzuonstev
  • 6,824
  • 7
  • 26
  • 56
  • 1
    Possible duplicate of [How do I write JSON data to a file?](https://stackoverflow.com/questions/12309269/how-do-i-write-json-data-to-a-file) – Yevhen Kuzmovych Apr 30 '19 at 11:51

1 Answers1

-2

Does this work for you?

import json

lst = [1,2,3]
file_name = 'test.json'
with open(file_name, 'w') as f:
    f.write(json.dumps(lst))
3UqU57GnaX
  • 389
  • 3
  • 12