Skip to content

Instantly share code, notes, and snippets.

@InputBlackBoxOutput
Last active September 6, 2021 17:12
Show Gist options
  • Save InputBlackBoxOutput/86757feb0e7d58b7f5f143710ff0d4c8 to your computer and use it in GitHub Desktop.
Save InputBlackBoxOutput/86757feb0e7d58b7f5f143710ff0d4c8 to your computer and use it in GitHub Desktop.
Convert a text file or CSV file into a JSON file
import json
seperator = ','
with open("text.txt", encoding='utf-8') as file:
data = file.read().splitlines()
print(len(data))
json_object = {}
for i, each in enumerate(data):
json_object[i] = each.split(seperator)
with open('JSON.json', 'w') as file:
json.dump(json_object, file)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment