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
1 month ago - Return a JSON string representation of a Python data structure, o. For example: >>> json.JSONEncoder().encode({"foo": ["bar", "baz"]}) '{"foo": ["bar", "baz"]}' ... Encode the given object, o, and yield each string representation as available.
๐ŸŒ
PyPI
pypi.org โ€บ project โ€บ json-lines
json-lines ยท PyPI
Handling broken (cut at some point) files is enabled by passing broken=True to json_lines.reader or json_lines.open. Broken lines are skipped (only logging a warning), and reading continues from the next valid position.
      ยป pip install json-lines
    
Published ย  Nov 21, 2018
Version ย  0.5.0
Discussions

python - Loading and parsing a JSON file with multiple JSON objects - Stack Overflow
I am trying to load and parse a JSON file in Python. But I'm stuck trying to load the file: import json json_data = open('file') data = json.load(json_data) Yields: ValueError: Extra data: line 2 More on stackoverflow.com
๐ŸŒ stackoverflow.com
Python conversion from JSON to JSONL - Stack Overflow
If you have a list of JSONs, like in your example, you can still search and replace with RegEx, take the negative lookahead "?!", see Stack Overflow Find 'word' not followed by a certain character with \n(?!\s*\{) so that you also skip the spaces after a linebreak: ... Clean the rest of the unneeded characters as you showed it yourself, but take RegEx for it, and you could also do this RegEx replacement automatically with Python ... More on stackoverflow.com
๐ŸŒ stackoverflow.com
Reading a large (30.6G) JSONL file
There's no good off-the-shelf solution for this. JSON files are simply not designed for that. There's a couple of "lazy" json parsers or "iterative" parsers, but in the end it comes down to what your data looks like. It's often better / easier to parse out the higher objects yourself. For example if your data is a massive list of lists, you could manually search for the "[]" characters and pass the results into json.loads as a "stream". More on reddit.com
๐ŸŒ r/learnpython
14
5
April 21, 2021
There's no way to have multi-line strings in a Json file, right? How could I deal with this limitation when getting Python to read from such a file.
you can have multiline strings in json. this is the contents of sample.json {"text": "hello world\n2nd line"} and some python that reads the file import json with open("/tmp/sample.json", "rb") as f: x = json.loads(f.read()) the value of x["text"] is a multiline string. More on reddit.com
๐ŸŒ r/learnpython
9
5
September 13, 2017
๐ŸŒ
Readthedocs
jsonlines.readthedocs.io
jsonlines โ€” jsonlines documentation
The original line itself is stored on the exception instance as the .line attribute, and the line number as .lineno. This class subclasses both jsonlines.Error and the built-in ValueError.
๐ŸŒ
GitHub
github.com โ€บ rmoralespp โ€บ jsonl
GitHub - rmoralespp/jsonl: A lightweight Python library for handling jsonlines files ยท GitHub
2 weeks ago - When reading, if the file extension is not recognized, jsonl falls back to magic-number detection to identify the compression format automatically. # Install dev dependencies pip install --group=test --upgrade # Run tests python -m pytest tests/ python -m pytest tests/ --cov # run with coverage reporting # Lint pip install --group=lint --upgrade ruff check .
Author ย  rmoralespp
๐ŸŒ
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 - JSON data often takes the form of newline-delimited JSON Lines (also known as NDJSON) to represent multiple records in a dataset. Reading JSON Lines data into a dataframe is a common first step in data processing. In this post, we compare the performance and functionality of Python APIs for ...
๐ŸŒ
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 - Itโ€™s a file type specification where each line is a JSON object. Just imagine a bunch of stacked up dictionaries. Hereโ€™s an example with 4 records:
Find elsewhere
๐ŸŒ
Softhints
softhints.com โ€บ python-convert-json-to-json-lines
Python convert normal JSON to JSON separated lines 3 examples - Softhints
December 14, 2024 - import jsonlines import json with open('/home/user/data/normal_json.json', 'r') as f: json_data = json.load(f) with jsonlines.open('/home/user/data/json_lines2.jl', 'w') as writer: writer.write_all(json_data) ... {"id": 1, "label": "A", "size": "S"} {"id": 2, "label": "B", "size": "XL"} {"id": 3, "label": "C", "size": "XXl"} ...
๐ŸŒ
Rowzero
rowzero.com โ€บ blog โ€บ open-jsonl-file-format
Easily Open JSONL Files - Guide to JSON Lines Format - Row Zero โ€“ the spreadsheet for modern cloud data
October 24, 2024 - See how to open JSONL files in a spreadsheet, read JSONL in python, convert JSON to JSONL and CSV to JSONL, and the advantages of JSON lines format.
๐ŸŒ
Real Python
realpython.com โ€บ python-json
Working With JSON Data in Python โ€“ Real Python
August 20, 2025 - 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.
๐ŸŒ
GitHub
github.com โ€บ wbolster โ€บ jsonlines
GitHub - wbolster/jsonlines: python library to simplify working with jsonlines and ndjson data ยท GitHub
python library to simplify working with jsonlines and ndjson data - wbolster/jsonlines
Starred by 308 users
Forked by 31 users
Languages ย  Python
๐ŸŒ
W3Schools
w3schools.com โ€บ python โ€บ python_json.asp
Python JSON
Python Examples Python Compiler Python Exercises Python Quiz Python Challenges Python Server Python Syllabus Python Study Plan Python Interview Q&A Python Bootcamp Python Certificate Python Training ... JSON is a syntax for storing and exchanging data.
๐ŸŒ
Jsonltools
jsonltools.com โ€บ jsonl-parser
JSONL Parser: Complete Guide to Parsing JSON Lines Format - JSONL Tools
Learn how to parse JSONL files with comprehensive examples in Python, JavaScript, Java, and Go. Complete guide to JSONL parsing with performance tips and best practices.
๐ŸŒ
freeCodeCamp
freecodecamp.org โ€บ news โ€บ how-to-parse-json-in-python-with-examples
How to Parse JSON in Python โ€“ A Complete Guide With Examples
November 2, 2024 - The final example shows that valid JSON parses successfully and returns a dictionary instead of None. JSON parsing failed: Expecting ',' delimiter Error at line 1, column 19 Result 1: None JSON parsing failed: Expecting ',' delimiter Error at line 1, column 28 Result 2: None JSON parsing failed: Expecting property name enclosed in double quotes Error at line 1, column 29 Result 3: None Result 4: {'name': 'Sarah', 'age': 28}
๐ŸŒ
Shamsur Rahim
shamsurrahim.wordpress.com โ€บ 2017 โ€บ 04 โ€บ 17 โ€บ how-to-read-jsonl-file-in-python
How to read JSONL file in Python | Shamsur Rahim
April 22, 2020 - Today, I will only discuss on how to read a JSONL file in python. So if you want to know more about JSONL, then you can check here. ... import json_lines with open('fileName.jsonl', 'rb') as f: # opening file in binary(rb) mode for item in json_lines.reader(f): print(item) #or use print(item['X']) for printing specific data
๐ŸŒ
NCBI
ncbi.nlm.nih.gov โ€บ datasets โ€บ docs โ€บ v2 โ€บ reference-docs โ€บ file-formats โ€บ metadata-files โ€บ tools-for-jsonl
Tools for JSON and JSON Lines - NCBI
JSON Lines is less widely adopted; however, the format consists of one JSON value per line, and therefore, is easily parsed with JSON libraries. For example, in Python:
๐ŸŒ
Unpaywall
support.unpaywall.org โ€บ support โ€บ solutions โ€บ articles โ€บ 44001867300-how-do-i-read-jsonl-files-
How do I read JSONL files? : Unpaywall
The downside is that the file contents as a whole aren't valid JSON, so most tools that work with JSON can't read it directly. 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.
๐ŸŒ
Jsonlines
jsonlines.org โ€บ on_the_web
JSON Lines |On The Web
October 29, 2025 - OpenAI Evals is an AI Evaluations (Evals) application using JSON Lines to pass in bulk data. petl is a general purpose Python package for extracting, transforming and loading tables of data.