Reading JSON file from url using ijson

187 views Asked by At

This is the code that I have been trying:

import ijson
import urllib.request

with urllib.request.urlopen(some_link) as read_file:
        path_array = ijson.items(read_file, object_in_json)

but I get this error:

(b'lexical error: invalid char in json text.\n                                       \x1f\x8b\x08                     (right here) ------^\n',)
1

There are 1 answers

0
Nicolò Teseo On

Probably links are not supported by that library.

I advice you to use the requests module. So install it launching pip install requests.

Then, in your .py file:

import requests
response = requests.get(url)
json = response.json()