Use json.load()
, not json.loads()
, if your input is a file-like object (such as a TextIOWrapper).
Given the following complete reproducer:
import json, tempfile
with tempfile.NamedTemporaryFile() as f:
f.write(b'{"text": "success"}'); f.flush()
with open(f.name,'r') as lst:
b = json.load(lst)
print(b['text'])
...the output is success
.