You have a JSON Lines format text file. You need to parse your file line by line:

import json

data = []
with open('file') as f:
    for line in f:
        data.append(json.loads(line))

Each line contains valid JSON, but as a whole, it is not a valid JSON value as there is no top-level list or object definition.

Note that because the file contains JSON per line, you are saved the headaches of trying to parse it all in one go or to figure out a streaming JSON parser. You can now opt to process each line separately before moving on to the next, saving memory in the process. You probably don't want to append each result to one list and then process everything if your file is really big.

If you have a file containing individual JSON objects with delimiters in-between, use How do I use the 'json' module to read in one JSON object at a time? to parse out individual objects using a buffered method.

Answer from Martijn Pieters on Stack Overflow
People also ask

Who uses JSONL files?
JSON Lines files are often used by data engineers, data scientists, and analysts because JSONL is good at processing and managing large datasets. JSONL is good for real-time data and streaming applications.
🌐
rowzero.com
rowzero.com › blog › open-jsonl-file-format
Easily Open JSONL Files - Guide to JSON Lines Format | Row Zero
What is the best way to visualize JSONL data?
Row Zero is a good JSONL viewer because it opens JSONL files in a spreadsheet format that makes it easy to view, filter, analyze, and troubleshoot large datasets.
🌐
rowzero.com
rowzero.com › blog › open-jsonl-file-format
Easily Open JSONL Files - Guide to JSON Lines Format | Row Zero
What is the JSONL file format?
The JSON Lines format stores one JSON object per line and is a very efficient file format for large datasets.
🌐
rowzero.com
rowzero.com › blog › open-jsonl-file-format
Easily Open JSONL Files - Guide to JSON Lines Format | Row Zero
🌐
Readthedocs
jsonlines.readthedocs.io
jsonlines — jsonlines documentation
Read and decode a line. The optional type argument specifies the expected data type. Supported types are dict, list, str, int, float, and bool. When specified, non-conforming lines result in InvalidLineError. By default, input lines containing null (in JSON) are considered invalid, and will cause InvalidLineError.
🌐
PyPI
pypi.org › project › json-lines
json-lines · PyPI
This is a tiny library for reading JSON lines (.jl) files, including gzipped and broken files.
      » pip install json-lines
    
Published   Nov 21, 2018
Version   0.5.0
🌐
Tim Santeford
timsanteford.com › posts › how-to-read-and-parse-jsonl-files-in-python
How to Read and Parse JSONL Files in Python - Tim Santeford
Iterating over lines: The file is read line by line to conserve memory, especially useful for large files. Parsing JSON: The json.loads function converts a JSON string into a Python dictionary (or list, depending on the content).
🌐
Rowzero
rowzero.com › blog › open-jsonl-file-format
Easily Open JSONL Files - Guide to JSON Lines Format | Row Zero
Python and JSON lines are often used together to work with big datasets. Here are a few how-tos to get started. It's easy to open and read JSONL files in Python using the Python json or jsonlines library
Find elsewhere
🌐
GeeksforGeeks
geeksforgeeks.org › python › read-json-file-using-python
Read JSON file using Python - GeeksforGeeks
We will be using Python’s json module, which offers several methods to work with JSON data. In particular, loads() and load() are used to read JSON from strings and files, respectively.
Published   September 15, 2025
🌐
Real Python
realpython.com › python-json
Working With JSON Data in Python – Real Python
August 20, 2025 - The dog_data dictionary contains a bunch of common Python data types as values. For example, a string in line 2, a Boolean in line 3, a NoneType in line 7, and a tuple in line 8, just to name a few. Next, convert dog_data to a JSON-formatted string and back to Python again.
🌐
Unpaywall
support.unpaywall.org › support › solutions › articles › 44001867300-how-do-i-read-jsonl-files-
How do I read JSONL files? : Unpaywall
You'll need some kind of wrapper script to handle the file line by line. In python, you could either read the file line by line and use the standard json.loads function on each line, or use the jsonlines library to do this for you.
🌐
Medium
sundararamanp.medium.com › a-relatively-faster-approach-for-reading-json-lines-file-into-pandas-dataframe-90b57353fd38
A relatively faster approach for reading json lines file into pandas dataframe | by Sundararaman Parameswaran | Medium
April 22, 2020 - Step 3: Now we will apply json loads function on each row of the ‘json_element’ column. ‘json.loads’ is a decoder function in python which is used to decode a json object into a dictionary.
🌐
NVIDIA Developer
developer.nvidia.com › blog › json-lines-reading-with-pandas-100x-faster-using-nvidia-cudf
JSON Lines Reading with pandas 100x Faster Using NVIDIA cuDF | NVIDIA Technical Blog
April 23, 2025 - The runs with pylibcudf used a CUDA async memory resource through RAPIDS Memory Manager (RMM). Throughput values were computed using the JSONL input file size and the reader runtime of the third repetition. Here are some examples from several Python libraries for invoking the JSON Lines reader:
🌐
Medium
galea.medium.com › how-to-love-jsonl-using-json-line-format-in-your-workflow-b6884f65175b
How to Love jsonl — using JSON Lines in your Workflow | by Alex Galea | Medium
April 9, 2024 - I use jsonl for dumping raw “source of truth” data. From there it can be loaded in and processed by any part of the application and, if needed, dumped into a relational format (e.g. Postgres, MySQL, CSV). Here are python functions that can be used to write and read jsonl:
🌐
Medium
nicholaszhan.com › line-em-up-a-guide-to-json-lines-7c43215b3b82
Line ’Em Up: A Guide to JSON Lines | by Nicholas Zhan | Medium
February 2, 2024 - You can do this programmatically ...(json_line + '\n') To read the JSON Lines file and process each entry, we can iterate over the lines in the file: # Reading from a JSON Lines file with open('sensor_data.jso...
Top answer
1 of 4
119

Note: Line separated json is now supported in read_json (since 0.19.0):

CopyIn [31]: pd.read_json('{"a":1,"b":2}\n{"a":3,"b":4}', lines=True)
Out[31]:
   a  b
0  1  2
1  3  4

or with a file/filepath rather than a json string:

Copypd.read_json(json_file, lines=True)

It's going to depend on the size of you DataFrames which is faster, but another option is to use str.join to smash your multi line "JSON" (Note: it's not valid json), into valid json and use read_json:

CopyIn [11]: '[%s]' % ','.join(test.splitlines())
Out[11]: '[{"a":1,"b":2},{"a":3,"b":4}]'

For this tiny example this is slower, if around 100 it's the similar, signicant gains if it's larger...

CopyIn [21]: %timeit pd.read_json('[%s]' % ','.join(test.splitlines()))
1000 loops, best of 3: 977 µs per loop

In [22]: %timeit l=[ json.loads(l) for l in test.splitlines()]; df = pd.DataFrame(l)
1000 loops, best of 3: 282 µs per loop

In [23]: test_100 = '\n'.join([test] * 100)

In [24]: %timeit pd.read_json('[%s]' % ','.join(test_100.splitlines()))
1000 loops, best of 3: 1.25 ms per loop

In [25]: %timeit l = [json.loads(l) for l in test_100.splitlines()]; df = pd.DataFrame(l)
1000 loops, best of 3: 1.25 ms per loop

In [26]: test_1000 = '\n'.join([test] * 1000)

In [27]: %timeit l = [json.loads(l) for l in test_1000.splitlines()]; df = pd.DataFrame(l)
100 loops, best of 3: 9.78 ms per loop

In [28]: %timeit pd.read_json('[%s]' % ','.join(test_1000.splitlines()))
100 loops, best of 3: 3.36 ms per loop

Note: of that time the join is surprisingly fast.

2 of 4
28

If you are trying to save memory, then reading the file a line at a time will be much more memory efficient:

Copywith open('test.json') as f:
    data = pd.DataFrame(json.loads(line) for line in f)

Also, if you import simplejson as json, the compiled C extensions included with simplejson are much faster than the pure-Python json module.

🌐
Reddit
reddit.com › r/learnpython › reading a json file; readline() works as predicted, readlines() does not.
r/learnpython on Reddit: reading a json file; readline() works as predicted, readlines() does not.
February 28, 2013 -

The json is twitter stream

here is my code:

    output = open("path\\filename.json","r")
    output.readline()

works as expected. When I use readline(), each time, a new line from the twitter stream is printed.

But this code

    output.readlines()

yields this:

ERROR - failed to write data to stream pyreadline.console.console.Console object at 0x010B9FB0

Why isn't readlines reading all of the lines?

For what it's worth, I want to read all of the lines from the twitterStream json, and then be able to select some lines (maybe randomly, maybe the first 10) to save as a new json file.

🌐
PYnative
pynative.com › home › python › json › python parse multiple json objects from file
Python Parse multiple JSON objects from file | Solve ValueError: Extra data
May 14, 2021 - Read the file line by line because each line contains valid JSON. i.e., read one JSON object at a time. Convert each JSON object into Python dict using a json.loads()
🌐
Python
docs.python.org › 3 › library › json.html
JSON encoder and decoder — Python 3.14.3 documentation
Deserialize fp to a Python object using the JSON-to-Python conversion table. ... fp (file-like object) – A .read()-supporting text file or binary file containing the JSON document to be deserialized.