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?

0

2 Answers 2

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'}
Sign up to request clarification or add additional context in comments.

2 Comments

much better would be data = resp.json()
@buran Not sure it would be much better, but yes, it would definitely be more concise :) Updated the answer. Thanks!
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'}

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.