The error AttributeError: ‘Str’ Object Has No Attribute ‘Read Json’ shows that Python is trying to call a JSON reader on a plain string.
What AttributeError: ‘Str’ Object Has No Attribute ‘Read Json’ Means
When Python shows this AttributeError, it is telling you that a value of type str is being used as if it had a method named
read_json (or a very similar name such as readJson or ReadJson). A str value only has string
methods such as split, strip, and upper. It has no built-in JSON reader. That method usually belongs to
a library such as pandas, polars, or a custom helper object.
In short, the value on the left of the dot is a plain text value, but the code is written as if that value were a file object, a DataFrame,
or some other JSON-aware object. Python protects you by raising an AttributeError instead of silently doing the wrong thing.
A close cousin of this message is attributeerror: 'str' object has no attribute 'read json' where the entire error text appears in
lowercase. The meaning is the same. The casing comes from the way you typed the method name, but the core problem always points to the type of
the value on the left side of the dot.
Where This Json Attribute Error Usually Comes From
This kind of AttributeError tends to appear in a small set of patterns. Once you match your code to one of these patterns, the fix is usually
direct and quick.
- Using json.load On A String — The
json.loadfunction expects a file-like object with aread()method, but the code passes a plain JSON string instead of an open file. - Calling read_json On A String Path — The code does something like
path.read_json()wherepathis just a string containing a filename instead of callingpd.read_json(path). - Mixing Up DataFrame And Module Methods — A project uses
pandas, but a string variable ends up on the left of.read_jsonthrough a copy-paste or refactor slip. - Shadowing Library Names With Strings — A variable named
pandas,pd, ordatais set to a string later in the script, and the next call to.read_jsonhits that string instead of the real library or object. - Passing The Wrong Layer Of A Response Object — Code that uses
requestsor another HTTP client sometimes passesresponse.textto a method that expects a file-like object, then tries to call.read_jsonon it.
These issues all share one root cause: the variable type silently changed from “JSON reader” to “plain string”. Once you track down where that
swap happened, you can straighten out the call so the correct object owns the method.
Fixing The Error With The Python Json Module
A large share of cases come from mixing up json.load and json.loads. The spelling is similar, but the two functions
accept different kinds of input. One works with open file objects, and the other works with strings.
When You Have A File On Disk
If your code already has a JSON file stored on disk, the clean pattern is to open the file and pass that open handle to json.load.
import json
with open("data.json", "r", encoding="utf-8") as f:
data = json.load(f)
In this pattern, the file handle f has a read() method, so json.load can pull bytes from the file in
chunks. No read_json attribute is involved, so the AttributeError never appears.
When You Only Have A Json String
Many APIs return JSON text instead of a file. In that case, you should use json.loads, which accepts a string directly.
import json
import requests
response = requests.get("https://example.com/data.json")
json_text = response.text # this is a str
data = json.loads(json_text) # no file handle needed
When you use json.loads like this, you avoid calling JSON methods on strings yourself. The function handles the parsing, and you
end up with Python dictionaries and lists ready for the rest of your code.
A Quick Checklist For Json Module Fixes
- Check Your Function Name — Use
json.loadonly with open file handles and usejson.loadswhen you already have JSON text in a string. - Verify Variable Types — Print
type(value)for any variable near the failing line to confirm whether it is a string, a file, or something else. - Avoid Hidden Reassignments — Keep the names
json,data, andfilefor their real purposes so they do not get reused for unrelated strings later in the script.
Fixing The Error When Using Pandas Read Json With Files Or Strings
Many developers bump into the error while working with pandas.read_json. The method is designed to sit either on the top-level
pandas module (pd.read_json) or, in older patterns, on a class method, not on a plain string.
Correct Ways To Load Json Into Pandas
Here are several patterns that keep the types aligned so that read_json ends up on the right object.
- Read From A File Path — Use
pd.read_json("data.json"), lettingpandasopen the file internally instead of calling any JSON reader on the path string. - Read From A Json String — Wrap the string with
io.StringIOso thatpandassees a file-like object with aread()method. - Read From A Url — Pass the URL directly to
pd.read_jsonwhen the server returns straight JSON;pandashandles the request and parsing.
import pandas as pd
from io import StringIO
json_text = '{"name": "Ada", "age": 36}'
# From a JSON string
df = pd.read_json(StringIO(json_text))
# From a file path
df_file = pd.read_json("data.json")
In each pattern, the call is attached to pd, not to a string. The library owns the method, and you keep strings in their role as
data or paths, not as JSON readers.
Common Pandas Pitfalls That Trigger The Error
- Calling read_json On A Path String — Code like
file_path.read_json()fails becausefile_pathis a plain string; move the path intopd.read_json(file_path)instead. - Shadowing The pd Alias — Assigning a string to
pdlater in the script makespd.read_json()crash with the same AttributeError, becausepdno longer points to the library. - Confusing DataFrame Methods And Module Functions — In older code,
pandasallowedDataFrame.from_recordsand similar calls; mixing those with strings can leave a stray.read_jsonon the wrong value.
If you see the exact text attributeerror: 'str' object has no attribute 'read json' alongside a pandas import, scan for any place where a path, URL, or JSON string ends up on the left of a dot. Every .read_json call should hang from pd or another JSON-capable object, never from a string.
Avoiding ‘Str’ Object Has No Attribute ‘Read Json’ Errors In New Code
Once the current bug is fixed, it pays to add small habits that make this whole class of AttributeError less likely in later refactors. The aim
is to keep a clear line between “data” values and “tool” objects that operate on that data.
- Use Clear Variable Names — Reserve names like
json_text,json_path, andresponse_bodyfor strings and names likejson_fileorbufferfor file-like objects. - Add Lightweight Type Hints — Mark function parameters as
str,IO[str], orPathso that editors and linters can warn you when a string is used as a JSON reader. - Keep Json Loading In One Place — Centralize JSON parsing in a small helper that returns plain Python objects; call that helper from the rest of your code instead of sprinkling
read_jsoncalls everywhere. - Write Small Tests Around Json Paths — A quick unit test that loads a sample file through your helper will catch AttributeError messages the moment a refactor swaps a type.
- Log Types During Debugging — When something feels off, add short logs with
type(value)near JSON calls to confirm that strings, files, and DataFrames are in the places you expect.
These habits shift the bug from a runtime surprise to a quick edit caught by your tools. Over time your project will gather a small set of
stable patterns for JSON handling, which makes new code easier to read and safer to change.
Quick Reference Table For Json Attribute Errors
The table below groups several common situations that resemble AttributeError messages around JSON handling, along with a short hint for the
fix. This can sit near your editor while you clean up a series of related issues.
| Scenario | Likely Cause | Quick Fix |
|---|---|---|
attributeerror: 'str' object has no attribute 'read json' |
String used where a JSON reader object or module call is expected. | Move the call to json.loads or pd.read_json and pass the string as an argument. |
'str' object has no attribute 'read' |
json.load given a string instead of an open file handle. |
Open the file with open(...) and pass the handle to json.load, or switch to json.loads. |
'str' object has no attribute 'json' |
.json() called on a string instead of an HTTP response object. |
Call .json() on the original response, or pass the string into json.loads. |
'str' object has no attribute 'keys' |
Looping over a dict but treating its keys (strings) as dictionaries. | Work with the dict itself or call json.loads earlier so that nested data keeps its structure. |
module 'pandas' has no attribute 'read_json' |
Old pandas version, name clash, or typo in the function name. | Upgrade pandas, check imports, and verify that the name in the call matches the installed version. |
When you see any version of this AttributeError, pause and ask one simple question: “What is the type of the value on the left side of the
dot?” Once that answer is clear, the correction usually boils down to moving a method call to the right object or switching from a string-only
function to a file-based one.
