A valid JSON document can contain a scalar instead of an object.
import json
for sample in ['{"id": 8}', 'false']:
value = json.loads(sample)
print(isinstance(value, dict))
# True
# FalseDecoding successfully tells you the syntax was valid. After decoding, check the shape. A malformed line raises json.JSONDecodeError.
Implement object_lines(text). Each line may contain one JSON value. Return all decoded objects in order, including empty objects. Skip blank lines, malformed JSON, arrays and scalars. One bad line must not discard the following lines.
object_lines('{"n":1}\noops\n[]\n{}') # [{"n": 1}, {}]