Python read jsonlines format file
A JSON lines file is a format that facilitates the storage of structured data and can process one record at a time. Can be used as a log file or other. There is a ' \ n ' delimiter between each JSON data.
Specific information can be viewed http://jsonlines.org/
Before the crawler stored data, the use of this format file, but at the time of reading, Python built-in JSON function, will be error;
Two libraries were found on the Web:
1, Jsonlines, document: https://jsonlines.readthedocs.io/en/latest/,
GitHub Address: Https://github.com/wbolster/jsonlines
2, Json-lines, GitHub address: Https://github.com/TeamHG-Memex/json-lines
In the Anaconda environment and the Pycharm library installation, both libraries cannot be found temporarily, so you can use only the PIP command
Jsonlines specific reading code is as follows:
1 import Jsonlines 2 3 with open ( " XXXX.JL ", " r+ ", Encoding=" UTF8 " ) as F: 4 for item In Jsonlines. Reader (f): 5 print (item)
Json-lines specific read code: https://shamsurrahim.wordpress.com/2017/04/17/how-to-read-jsonl-file-in-python/
1 Import Json_lines 2 3 with open ('filename.jsonl'rb' 4 for inch Json_lines.reader (f): 5 Print (item)
Python reads jsonlines format files