Displaying better error message than “No JSON object could be decoded”

后端 未结 11 1082
既然无缘
既然无缘 2020-11-30 23:05

Python code to load data from some long complicated JSON file:

with open(filename, \"r\") as f:
  data = json.loads(f.read())

(note: the be

11条回答
  •  青春惊慌失措
    2020-12-01 00:02

    Just hit the same issue and in my case the problem was related to BOM (byte order mark) at the beginning of the file.

    json.tool would refuse to process even empty file (just curly braces) until i removed the UTF BOM mark.

    What I have done is:

    • opened my json file with vim,
    • removed byte order mark (set nobomb)
    • save file

    This resolved the problem with json.tool. Hope this helps!

提交回复
热议问题