I'm using the ijson library in Python to parse a large JSON file and I need to find the position in the file where specific data is located. I want to use file.tell() to get the current position of the file reader during the parsing process. But it's only giving me the length of the file.
from ijson import parse
with open('file','r') as f:
for a, b, c in parse(f):
print(f.tell())
ijson.parse
is using buffered reads of the source file:
>>> help(ijson.parse)
Help on function parse in module ijson.common:
parse(source, buf_size=65536, **config)
If your file is smaller than 64K it will look like f.tell()
is returning the file size.
If you use parse(f, buf_size=1)
the f.tell()
should be accurate, but parsing will likely be slower.