Comment lire un format jsonl
Bonsoir,
La documentation (http://jsonlines.readthedocs.io/en/latest/) n'est pas assez claire pour moi. Je ne comprends pas comment on lit les objets.
En réécrivant ce code ci-dessous, j'ai une erreur alors que je voulais juste afficher le 'a' car l'erreur est au niveau du < for obj in reader: [....] > et là la doc n'a pas décrit la suite.
Code:
1 2 3 4 5 6
|
import jsonlines, json
with jsonlines.open('example.jsonl') as reader:
print(reader)
for obj in reader:
print('a') |
Citation:
Traceback (most recent call last):
<jsonlines.Reader at 0x49a330 wrapping 'example.jsonl'>
File "C:\Users\synapse01\AppData\Local\Programs\Python\Python36-32\lib\site-packages\jsonlines\jsonlines.py", line 158, in read
value = self._loads(line)
File "C:\Users\synapse01\AppData\Local\Programs\Python\Python36-32\lib\json\__init__.py", line 354, in loads
return _default_decoder.decode(s)
File "C:\Users\synapse01\AppData\Local\Programs\Python\Python36-32\lib\json\decoder.py", line 339, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "C:\Users\synapse01\AppData\Local\Programs\Python\Python36-32\lib\json\decoder.py", line 355, in raw_decode
obj, end = self.scan_once(s, idx)
json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes: line 2 column 1 (char 2)
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:/Users/synapse01/AppData/Local/Programs/Python/Python36-32/dit/translation_corpora/translation_google_api_corpus_multinli.py", line 74, in <module>
for obj in reader:
File "C:\Users\synapse01\AppData\Local\Programs\Python\Python36-32\lib\site-packages\jsonlines\jsonlines.py", line 203, in iter
skip_empty=skip_empty)
File "C:\Users\synapse01\AppData\Local\Programs\Python\Python36-32\lib\site-packages\jsonlines\jsonlines.py", line 163, in read
six.raise_from(exc, orig_exc)
File "<string>", line 2, in raise_from
jsonlines.jsonlines.InvalidLineError: line contains invalid json: Expecting property name enclosed in double quotes: line 2 column 1 (char 2) (line 1)
Process finished with exit code 1
Merci