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
๐ŸŒ
Python
docs.python.org โ€บ 3 โ€บ library โ€บ json.html
JSON encoder and decoder โ€” Python 3.14.3 documentation
$ echo '{"json": "obj"}' | python -m json { "json": "obj" } $ echo '{1.2:3.4}' | python -m json Expecting property name enclosed in double quotes: line 1 column 2 (char 1) Changed in version 3.5: The output is now in the same order as the input. Use the --sort-keys option to sort the output of dictionaries alphabetically by key.
๐ŸŒ
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.
๐ŸŒ
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
๐ŸŒ
Readthedocs
jsonlines.readthedocs.io
jsonlines โ€” jsonlines documentation
The sort_keys argument can be used to sort keys in json objects, and will produce deterministic output. For more control, provide a a custom encoder callable using the dumps argument. The callable must produce (unicode) string output. If specified, the compact and sort arguments will be ignored. When the flush argument is set to True, the writer will call fp.flush() after each written line. ... Close this reader/writer. This closes the underlying file if that file has been opened by ...
๐ŸŒ
PyPI
pypi.org โ€บ project โ€บ json-lines
json-lines ยท PyPI
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 json_lines.open('file.jl.gz', broken=True) as f: for item in f: print(item['x']) License is MIT. ... Download the file for your platform. If you're not sure which to choose, learn more about installing packages. ... Filter files by name, interpreter, ABI, and platform.
      ยป pip install json-lines
    
Published ย  Nov 21, 2018
Version ย  0.5.0
๐ŸŒ
freeCodeCamp
freecodecamp.org โ€บ news โ€บ python-read-json-file-how-to-load-json-from-a-file-and-parse-dumps
Python Read JSON File โ€“ How to Load JSON from a File and Parse Dumps
October 27, 2020 - You just need to "dive deeper" into the structure of the dictionary by using the necessary keys and indices. You can use the original JSON file/string as a visual reference. This way, you can access, modify, or delete any value. ๐Ÿ’ก Tip: Remember that we are working with the new dictionary. The changes made to this dictionary will not affect the JSON file. To update the content of the file, we need to write to the file. Let's see how you can write to a JSON file. The first line of the with statement is very similar.
Find elsewhere
๐ŸŒ
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 - JSON-lines is a widely used file format other than CSV. The difference between JSON-lines and JSON file is only that the former contains multiple JSON objects separated by newline.
๐ŸŒ
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()
๐ŸŒ
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).
๐ŸŒ
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.

๐ŸŒ
Scaler
scaler.com โ€บ home โ€บ topics โ€บ read, write, parse json file using python
Read, Write, Parse JSON File Using Python - Scaler Topics
April 17, 2024 - Weโ€™ll implement the code to open and read the json file ... Proceed by using the results of json.load() as a normal Python dictionary, and print the contents! Hereโ€™s a sample json file. (example.json) ... The output shows us the contents of the JSON file, which were obtained after traversing it line by line.
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ how-to-read-json-file-in-python
How to read JSON file in Python
Read the json file using load() and put the json data into a variable. Use the data retrieved from the file or simply print it as in this case for simplicty. import json with open('persons.json') as f: data = json.load(f) print(data) {'name': 'Karan', 'languages': ['English', 'French']} ... ...
๐ŸŒ
Vertabelo Academy
academy.vertabelo.com โ€บ course โ€บ python-json โ€บ reading-json-files โ€บ reading-json-files โ€บ reading-a-json-file
How to Read and Write JSON Files in Python | Learn Python | Vertabelo Academy
If any of this is new to you, we recommend that you check out our course Python Basics Part 2. We have some customer data from our firm's online shops. Let's look at it. Read the file named customer1.json as a text file into memory and print the file contents. ... Our website uses cookies. By using this website, you agree to their use in accordance with the browser settings.You can modify your browser settings on your own.
๐ŸŒ
W3Schools
w3schools.com โ€บ python โ€บ python_json.asp
Python JSON
Python has a built-in package called json, which can be used to work with JSON data. ... If you have a JSON string, you can parse it by using the json.loads() method.
๐ŸŒ
Python Examples
pythonexamples.org โ€บ python-read-json-file
Python Read JSON File
import json fileObject = open("data.json", "r") jsonContent = fileObject.read() aList = json.loads(jsonContent) print(aList[0]) print(aList[0]['c']) ... In this Python JSON Tutorial, we learned how to read JSON file in Python and access values from the JSON 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