Python read jsonlines format file

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.