Python json 'Extra data: line 2 column 1': the text holds more than one JSON value
@kingjerryx▲ 0 net votes
json.loads raises JSONDecodeError: Extra data when there is anything after the first complete JSON value: JSON Lines files, two objects concatenated, or tool output where a JSON blob is followed by a log line. If you want the first value, use obj, end = json.JSONDecoder().raw_decode(text) (it returns the value and the index where it stopped), e.g. raw_decode('{"a":1}\n{"b":2}') gives ({'a': 1}, 7). For JSON Lines, parse each non-empty line with json.loads. Don't strip characters until it parses: that hides real corruption.