0

I have a site, with only JSON data. And i need to read this data with python.

So i need to know, how can i load an online JSON.

import json

f = "https://api.npoint.io/7872500d7eef44a03194"

data = json.load(f)

So how can this work? And then how can i check internet connection errors?

Balla Botond
  • 55
  • 11

2 Answers2

1

With requests library:

import requests

f = "https://api.npoint.io/7872500d7eef44a03194"
data = requests.get(f).json()

data

Output:

{'sample': 'this is only a sample'}
perl
  • 9,826
  • 1
  • 10
  • 22
0

You could use below for API calls

import requests

url = "https://api.npoint.io/7872500d7eef44a03194"
response = requests.request('get', url)
print(json.loads(response.text))

Output

{'sample': 'this is only a sample'}
blackraven
  • 5,284
  • 7
  • 19
  • 45