You do not want to specify "rb" because the binary representation of the file cannot be read by the JSON module. You probably want to encode "utf-8" and "read". EDIT: I initially said that both of these defaults, but I was informed that many operating systems have different default encodings and that Python uses the default system parameter in open (). Therefore, I would recommend setting the encoding parameter explicitly as "utf-8".
json supports loading from an open file using "json.load" instead of "json.loads", which is loaded from a line, so we can skip the read-as-how text and go directly to JSON. I do not think that you will want to “load” individual lines, as this will probably not be valid JSON.
import json
source share