I could not load the file with the json module either:
File /srv/home/seid/miniconda3/lib/python3.9/json/decoder.py:353, in JSONDecoder.raw_decode(self, s, idx)
344 """Decode a JSON document from ``s`` (a ``str`` beginning with
345 a JSON document) and return a 2-tuple of the Python
346 representation and the index in ``s`` where the document ended.
(...)
350
351 """
352 try:
--> 353 obj, end = self.scan_once(s, idx)
354 except StopIteration as err:
355 raise JSONDecodeError("Expecting value", s, err.value) from None
JSONDecodeError: Invalid control character at: line 2 column 914 (char 915)
Therefore, I tried it with pandas, as in one of the answers, to no avail:
File ~/.local/lib/python3.9/site-packages/pandas/io/json/_json.py:1133, in FrameParser._parse_no_numpy(self)
1129 orient = self.orient
1131 if orient == "columns":
1132 self.obj = DataFrame(
-> 1133 loads(json, precise_float=self.precise_float), dtype=None
1134 )
1135 elif orient == "split":
1136 decoded = {
1137 str(k): v
1138 for k, v in loads(json, precise_float=self.precise_float).items()
1139 }
ValueError: Unexpected character found when decoding array value (1)
I then opened the file in VSCode as a json and checked line 2 column 914 and found that after that column, there was a tab instead of spaces.
To fix this, I regex replaced all tabs with four spaces:
Side remark: I had a json with many hardcoded \n
linebreaks and thought that I would have to drop them as well, but these hardcoded \n
do not harm, you can keep them.
I saved the file, uploaded it again (overwriting the one that was there), and ran the code with json and with pandas again. Yet, the pandas error stayed the same, only the json error was new:
JSONDecodeError: Expecting value: line 11 column 5 (char 126773)
Going to that line with Ctrl
+G
and 11
, I found a bracket at the end of a list, and right before that in the line before, there was a wrong comma:
Without that comma, after uploading and overwriting again, the code ran through with both json and pandas. I only needed it as the dictionary that json loads so that I could avoid importing pandas.
json.load
. What you do next does not matter. – Ejaculate