Skip to main content
This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (
Help us improve Python packaging - Donate today!

Reading JSON lines (jl) files, recover broken files

Project Description

This is a tiny library for reading JSON lines (.jl) files, including gzipped and broken files.

JSON lines is a text file format where each line is a single json encoded item.


Reading a well-formed JSON lines file is a one-liner in Python. But the file can be broken: cut at some point (this happens when the process writing it is killed), or concatenated from several cut pieces (this happend when the process started appending to the same file again). Handling all this cases is not easy, especially if the file is compressed.

json-lines handles all this cases for you!


pip install json-lines

If ujson is installed, it is used to speed up json decoding (which is the main performance bottleneck even for gzipped files).


In order to read a well-formed json lined file, pass an open file as the first argument to json_lines.reader. The file can be opened in text or binary mode, but if it’s opened in text mode, the encoding must be set correctly:

import json_lines

with open('file.jl', 'rb') as f:
    for item in json_lines.reader(f):

There is also a helper function that recognizes “.gz” and “.gzip” extensions and opens them with gzip:

with'file.jl.gz') as f:
    for item in f:

Handling broken (cut at some point) files is enabled by passing broken=True to json_lines.reader or Broken lines are skipped (only logging a warning), and reading continues from the next valid position. This works both for compressed and uncompressed files:

with'file.jl.gz', broken=True) as f:
    for item in f:


License is MIT.

Release History

This version
History Node


History Node


History Node


History Node


History Node


Download Files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, Size & Hash SHA256 Hash Help File Type Python Version Upload Date
(3.9 kB) Copy SHA256 Hash SHA256
Source None Mar 28, 2017

Supported By

Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Google Google Cloud Servers DreamHost DreamHost Log Hosting