Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Large JSON file
#1
Hi All,

I build a program to read a JSON file from internet.
When the file is large , the python program hangs and I have to shut it down then run it again and it hangs again.
The programs works well with small JSON files.

import urllib.request, json myURL = "https://query1.finance.yahoo.com/v8/finance/chart/AAPL?symbol=INTC&period1=0&period2=9999999999&interval=1d" with urllib.request.urlopen(myURL) as url: data = json.loads(url.read().decode()) print(data)
any idea how to overcome this issue?

--Update.
I found that the program run file with the print(data)
it seems printing is causing a problem that I don't know !
Reply
#2
I guess you had some network issues. Try it again.

Later you may want to save the data.
Requesting data over and over again when testing, takes too much time.
Some providers limit their APIs with x requests per minute.
from urllib.request import urlopen import json import sys import pickle myURL = "https://query1.finance.yahoo.com/v8/finance/chart/AAPL?symbol=INTC&period1=0&period2=9999999999&interval=1d" timeout = 5 try: with urlopen(myURL, timeout=timeout) as request: data = request.read().decode() except Exception as e: print('Unable to request data from internet') sys.exit(1) try: data = json.loads(data) except Exception as e: print("Can't parse json string") sys.exit(1) else: print('Finished loading json') with open('finance.yahoo.com.pickle', 'wb') as fd: pickle.dump(data, fd) with open('finance.yahoo.com.json', 'w') as fd: json.dump(data, fd)
On my side it works. I get the data and the data can parsed with json.loads.
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply
#3
I think the problem is in printing data !

I modified your code a little bit
else: print('Finished loading json') print(data)
The program freeze after I added print(data)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Errors using json file RonR 5 901 Oct-28-2025, 03:00 PM
Last Post: buran
  How to optimize the speed of processing large JSON files in Python without using too sophia2005 3 894 Aug-02-2025, 03:25 PM
Last Post: snippsat
  Problems writing a large text file in python Vilius 4 1,968 Dec-21-2024, 09:20 AM
Last Post: Pedroski55
  JSON File - extract only the data in a nested array for CSV file shwfgd 2 2,208 Aug-26-2024, 10:14 PM
Last Post: shwfgd
  encrypt data in json file help jacksfrustration 1 3,484 Mar-28-2024, 05:16 PM
Last Post: deanhystad
  Parsing large JSON josvink66 5 3,098 Jan-10-2024, 05:46 PM
Last Post: snippsat
  parse json field from csv file lebossejames 4 2,956 Nov-14-2023, 11:34 PM
Last Post: snippsat
  Python Script to convert Json to CSV file chvsnarayana 8 6,297 Apr-26-2023, 10:31 PM
Last Post: DeaD_EyE
  Loop through json file and reset values [SOLVED] AlphaInc 2 7,414 Apr-06-2023, 11:15 AM
Last Post: AlphaInc
  Converted EXE file size is too large Rajasekaran 0 3,386 Mar-30-2023, 11:50 AM
Last Post: Rajasekaran

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020
This forum uses Lukasz Tkacz MyBB addons.
Forum use Krzysztof "Supryk" Supryczynski addons.