Retrieving data from api and storing in Json file (Python)

A simple project to store data from api in json file.

Get Started..

import urllib.request
import json
These are few free data
url = ('http://newsapi.org/v2/top-headlines?country=us&apiKey=***API-KEY***')
response = urllib.request.urlopen(url)
data = response.read().decode('UTF-8')
file = open("data.json","w")
file.write(data)

When you want to store the specific data.

new_data = json.loads(data)
get_articles = new_data['articles]
new_data_articles = json.dumps(get_articles)

Read data from json file convert into object

f = open("data.json", "r")
new_data = json.loads(f.read())

Thanks for Reading the Article!

Enjoy trying with new things

Follow me in Github, Twitter, Linkedin, Medium.

--

--

Full Stack Developer [Web | Mobile]

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store