Skip to content

Instantly share code, notes, and snippets.

@Melbourneandrew
Last active June 21, 2021 20:01
Show Gist options
  • Save Melbourneandrew/d6ed04bb5d7844048b5960a06b9c2922 to your computer and use it in GitHub Desktop.
Save Melbourneandrew/d6ed04bb5d7844048b5960a06b9c2922 to your computer and use it in GitHub Desktop.
Convert a text file(newline delimited) into an array saved in a json file
import json
f = open('input.txt', 'r+')
lines = [line for line in f.readlines()]
f.close()
words = []
for line in lines:
words.append(line.strip("\n"))
j = json.dumps(words)
with open("output.json", 'w') as outfile:
json.dump(words, outfile)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment