34 lines
894 B
Python
34 lines
894 B
Python
# encoding: utf-8
|
|
|
|
import json
|
|
|
|
# Default block size
|
|
SIZE_BLOCK = 32768
|
|
|
|
|
|
def json_reader(filepath, size_block=SIZE_BLOCK):
|
|
# Initiate reading
|
|
level = 0
|
|
in_string = False
|
|
loop = True
|
|
element = ""
|
|
with open(filepath) as f:
|
|
content = f.read(size_block)
|
|
while loop:
|
|
for char in content:
|
|
if char == '"':
|
|
in_string != in_string
|
|
if not in_string and char == "{":
|
|
level += 1
|
|
if level > 0:
|
|
element += char
|
|
if not in_string and char == "}":
|
|
level -= 1
|
|
if level == 0:
|
|
yield json.loads(element)
|
|
element = ""
|
|
# Reading next block
|
|
content = f.read(size_block)
|
|
if content == "":
|
|
loop = False
|