import json
def read_in_chunks(file_object, chunk_size=2048):
"""Lazy function (generator) to read a file piece by piece.
Default chunk size: 2k."""
while True:
data = file_object.read(chunk_size)
if not data:
break
yield data
f = open('productfeed.json','r')
for piece in read_in_chunks(f):
print piece
I have big file of 1gb, so i tried above method to read,it prints the values as string, but not able to read as json as it yields by size of 2k
and i tried this below code
students_d = json.loads(piece)
students = students_d["products"] # get list, process with for loop
for count, student in enumerate(students):
print(student["product_id"])
getting an error like this "ValueError: Unterminated string starting at: line 1 column 1012 (char 1011) "
Don't know how to proceed further, please someone can help me and not allowed to use ijson