How to convert JSON file to text file in Python

1 Answer

0 votes
# JSON File

'''

[
{"url": "https://www.collectivesolver.com/"},
{"url": "https://www.collectivesolver.com/31959/how-to-rotate-a-string-left-one-char-in-c"},
{"url": "https://www.collectivesolver.com/31889/how-to-generate-random-string-in-node-js"},
]

'''


with open('data.json') as json_file:
      data = json.load(json_file)
      with open('data.txt', 'w') as outfile:
           for u in data:
               outfile.write(u['url']) 
               outfile.write('\n') 
			   
		
# Text File
		
'''
run:

https://www.collectivesolver.com/
https://www.collectivesolver.com/31959/how-to-rotate-a-string-left-one-char-in-c
https://www.collectivesolver.com/31889/how-to-generate-random-string-in-node-js

'''

 



answered Jun 19, 2020 by avibootz
edited Jun 19, 2020 by avibootz
...