Last active
September 6, 2021 17:12
-
-
Save InputBlackBoxOutput/86757feb0e7d58b7f5f143710ff0d4c8 to your computer and use it in GitHub Desktop.
Convert a text file or CSV file into a JSON file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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