From your code, it looks like you're loading a JSON file which has JSON data on each separate line. read_json supports a lines argument for data like this:

data_df = pd.read_json('C:/Users/Alberto/nutrients.json', lines=True)

Note
Remove lines=True if you have a single JSON object instead of individual JSON objects on each line.

Answer from coldspeed95 on Stack Overflow
🌐
Pandas
pandas.pydata.org › docs › reference › api › pandas.read_json.html
pandas.read_json — pandas 3.0.1 documentation
Convert a JSON string to pandas object. This method reads JSON files or JSON-like data and converts them into pandas objects. It supports a variety of input formats, including line-delimited JSON, compressed files, and various data representations (table, records, index-based, etc.).
🌐
W3Schools
w3schools.com › python › pandas › pandas_json.asp
Pandas Read JSON
JSON is plain text, but has the ... programming, including Pandas. In our examples we will be using a JSON file called 'data.json'. Open data.json. ... Tip: use to_string() to print the entire DataFrame. ... JSON objects have the same format as Python dictionaries....
People also ask

How to load JSON file with Pandas?
You can load a JSON file using Pandas' read_json() method:
import pandas as pd df = pd.read_json('file.json')
This reads the JSON file into a Pandas DataFrame.
🌐
hevodata.com
hevodata.com › home › learn › data strategy
Pandas Load JSON: A Comprehensive Guide
How to read a JSON column in Pandas?
If you have a column in a DataFrame containing JSON-like data, use pd.json_normalize() to expand it:
import pandas as pd df = pd.DataFrame({'col': ['{"name": "John", "age": 30}', '{"name": "Jane", "age": 25}']}) df['col'] = df['col'].apply(pd.json_normalize)
This will convert the JSON strings in the column into structured data.
🌐
hevodata.com
hevodata.com › home › learn › data strategy
Pandas Load JSON: A Comprehensive Guide
How to load JSON string into Pandas DataFrame?
To load a JSON string into a Pandas DataFrame, use the pd.read_json() method with the json.loads() from Python’s built-in library:
import pandas as pd import json json_string = '{"name": "John", "age": 30}' df = pd.read_json(json.loads(json_string))
🌐
hevodata.com
hevodata.com › home › learn › data strategy
Pandas Load JSON: A Comprehensive Guide
🌐
GeeksforGeeks
geeksforgeeks.org › python › how-to-read-json-files-with-pandas
How to Read JSON Files with Pandas? - GeeksforGeeks
July 23, 2025 - JSON (JavaScript Object Notation) store data using key-value pairs. Reading JSON files using Pandas is simple and helpful when you're working with data in .json format.
🌐
Stack Abuse
stackabuse.com › reading-and-writing-json-files-in-python-with-pandas
Reading and Writing JSON Files in Python with Pandas
September 7, 2023 - In this article, we've covered how to read and write JSON files using Python's popular Pandas library - from local to remote files.
🌐
Spark By {Examples}
sparkbyexamples.com › home › pandas › pandas read json file with examples
Pandas Read JSON File with Examples - Spark By {Examples}
January 10, 2025 - Pandas read_json() function can be used to read JSON file or string into DataFrame. It supports JSON in several formats by using orient param. JSON is
🌐
Hevo
hevodata.com › home › learn › data strategy
Pandas Load JSON: A Comprehensive Guide
January 9, 2026 - Step 3: Load the JSON file in Pandas using the command below. import pandas as pd # you have to showcase the path to the file in your local drive. data = pd.read_json (‘pathfile_name.json') # print the loaded JSON into dataframe print(data)
Find elsewhere
🌐
Pandas
pandas.pydata.org › docs › dev › reference › api › pandas.read_json.html
pandas.read_json — pandas 3.0.0rc1+28.g37421be5bc documentation
Convert a JSON string to pandas object. This method reads JSON files or JSON-like data and converts them into pandas objects. It supports a variety of input formats, including line-delimited JSON, compressed files, and various data representations (table, records, index-based, etc.).
🌐
Reddit
reddit.com › r/learnpython › why parse json with python when pandas exists?
r/learnpython on Reddit: Why Parse JSON With Python When Pandas Exists?
December 28, 2023 -

Doing it with pure Python is interesting. It's incredibly flexible. It's time consuming. Is it silly?

I'm generally up for doing things the native way just because it's clean. But am I being silly not abstracting it away with some package? I was using a flavor of SQL I rarely touch the other day and was told "now with JSON support" and it actually wasn't terrible. SQL isn't exactly a bastion of exclusively new thinking. If we've already eliminated actual javascript for dealing with its JSON, why stop there? I am becoming a back in the good ole days when we used horses type of ass?

🌐
Medium
medium.com › @amit25173 › how-to-load-json-files-in-pandas-de7c66d75ba6
How to Load JSON Files in Pandas? | by Amit Yadav | Medium
March 6, 2025 - If you’re working with data, JSON files are everywhere — whether you’re dealing with APIs, configuration files, or structured logs. The good news? Pandas makes reading JSON ridiculously simple with just one function: read_json().
🌐
Scaler
scaler.com › home › topics › pandas › how to load and manipulate json files with pandas
How to Load and Manipulate JSON Files with Pandas - Scaler Topics
May 4, 2023 - We can use the read_json() function of the JSON module to read the data using the Pandas module. ... Refer to the next section for more details about the read_json() function. We can also read the JSON data using the JSON module in Python.
🌐
BMC Software
bmc.com › blogs › pandas-read-json-csv-files
Pandas: How To Read CSV & JSON Files – BMC Software | Blogs
Rather it is a file with multiple JSON records, one right after the other. import pandas as pd url = 'https://raw.githubusercontent.com/werowe/logisticRegressionBestModel/master/ct1.json' dfct=pd.read_json(url,lines=True)
🌐
Python Basics
pythonbasics.org › pandas-json
JSON with Python Pandas - Python Tutorial
Read json string files in pandas read_json(). You can do this for URLS, files, compressed files and anything that’s in json format. In this post, you will learn how to do that with Python.
🌐
Like Geeks
likegeeks.com › home › python › pandas › read json files using python pandas read_json
Read JSON files using Python Pandas read_json
In this tutorial, You'll learn how to use Pandas read_json() function in Python to read JSON files into DataFrame.
🌐
datagy
datagy.io › home › pandas tutorials › pandas reading & writing data › pandas read_json – reading json files into dataframes
Pandas read_json - Reading JSON Files Into DataFrames • datagy
February 24, 2023 - The 'columns' orientation provides a format that is like a Python dictionary, where the columns are the keys. The values are also dictionaries, where the keys are the index and the values are the values. Let’s see how you can read this data format: # Read a JSON String Into a Pandas DataFrame Using Columns Orientation import pandas as pd json_string = """{ "Name":{ "0":"Nik", "1":"Kate", "2":"Isla" }, "Age":{ "0":33.0, "1":"None", "2":37.0 }, "Sales":{ "0":33.33, "1":56.32, "2":43.44444 } }""" df = pd.read_json(json_string) print(df) # Returns: # Name Age Sales # 0 Nik 33 33.33000 # 1 Kate 33 56.32000 # 2 Isla 37 43.44444
Top answer
1 of 1
6

There are a few ways to do this a little more efficiently:

JSON module, then into Pandas

You could try reading the JSON file directly as a JSON object (i.e. into a Python dictionary) using the json module:

import json
import pandas as pd

data = json.load(open("your_file.json", "r"))
df = pd.DataFrame.from_dict(data, orient="index")

Using orient="index" might be necessary, depending on the shape/mappings of your JSON file.

check out this in depth tutorial on JSON files with Python.

Directly using Pandas

You said this option gives you a memory error, but there is an option that should help with it. Passing lines=True and then specify how many lines to read in one chunk by using the chunksize argument. The following will return an object that you can iterate over, and each iteration will read only 5 lines of the file:

df = pd.read_json("test.json", orient="records", lines=True, chunksize=5)

Note here that the JSON file must be in the records format, meaning each line is list like. This allows Pandas to know that is can reliably read chunksize=5 lines at a time. Here is the relevant documentation on line-delimited JSON files. In short, the file should have be written using something like: df.to_json(..., orient="records", line=True).

Not only does Pandas abstract some manual parts away for you, it offers a lot more options, such as converting dates correctly, specifying data type of each column and so on. Check out the relevant documentation.

Check out a little code example in the Pandas user guide documentation.

Another memory-saving trick - using Generators

There is a nice way to only have one file's contents in memory at any given time, using Python generators, which have lazy evaluation. Here is a starting place to learn about them.

In your example, it could look like this:

import os

# Get a list of files
files = sorted(os.listdir("your_folder"))
# Load each file individually in a generator expression
df = pd.concat(pd.read_json(file, orient="index") for f in files, ...)

The concatenation happens only once all files are read. Add any more parameters that are required where I left the .... The documentation for pd.concat are here.

🌐
KDnuggets
kdnuggets.com › how-to-convert-json-data-into-a-dataframe-with-pandas
How to Convert JSON Data into a DataFrame with Pandas - KDnuggets
This will convert it into a Python dictionary, and we can then create the DataFrame directly from the resulting Python data structure. However, it has a problem - it can only handle single nested data. So, for the above case, if you only use these steps with this code: import json import pandas as pd #Load the JSON data with open('books.json','r') as f: data = json.load(f) #Create a DataFrame from the JSON data df = pd.DataFrame(data['books']) df