Issue with python JSONDecodeError

Posted by Jingbiao on July 14, 2021, Reading time: 1 minute.

Issues


Json loader issue

  • When inputting json file into python with json.loads(_),
1
[json.loads(jline) for jline in open(path, "r").read().split('\n')]

line 36 of hm_data.py

  • a likely issue may be: JSONDecodeError: Expecting value: line 1 column 1 (char 0)

  • the reason is there might be blank line at the end of all the entries.

Simple Fixes

  • Remove all the empty lines

Alternative Fixes

Add if jline != "" into the line

1
2
[json.loads(jline) for jline in open(path, "r").read().split('\n')
 if jline != ""]