This error means Python tried to access a string with something other than an integer position or slice—often code such as data["name"] when data is actually a string. Check the value’s type at the failing line, then match your fix to its actual shape: decode JSON text, select a list element, iterate dictionary values, or use an integer index for text.
What the error means
Python strings are sequences of characters, so they support integer positions and slices, such as text[0] or text[1:4]. They do not support field-name indexing. If Python evaluates value["name"] while value is a string, it raises TypeError: string indices must be integers. The underlying cause is the mismatch between the object being indexed and the kind of index supplied—not necessarily a problem with the string’s contents. See Python’s built-in types documentation.
Find the value that has the wrong type
Use the traceback to locate the exact expression that failed. Immediately before it, print the type and representation of the object being indexed:
print(type(data))
print(repr(data))
type() shows whether the value is a string, dictionary, list, or another object. repr() shows its contents in a form that can make quotation marks, whitespace, and unexpected text easier to spot. Compare the result with what the code expects; changing an index without checking the input can merely hide the real mismatch.
#1 Best Overall
Choose the correction for the value’s actual shape
If it is JSON text, decode it first
A Python string containing JSON remains a string until decoded. For JSON text already in a variable, use json.loads():
import json
raw = '{"name": "Ada"}'
record = json.loads(raw)
print(record["name"])
For a file object, use json.load() instead:
import json
with open("record.json", encoding="utf-8") as file:
record = json.load(file)
print(record["name"])
These functions decode JSON; the result is not guaranteed to be a dictionary. JSON can represent an object, array, string, number, Boolean, or null. Check the decoded shape before using a key. Python’s JSON documentation describes the decoder and the values it can produce.
Rank #2
If it is a Requests response, decode the response body
When an HTTP response body contains JSON, call response.json() to decode it. Handle HTTP status separately: parsing a response body does not establish that the request succeeded.
response = requests.get(url)
response.raise_for_status()
record = response.json()
print(record["name"])
Requests documents Response.json() and status handling in its Quickstart.
Recommended Free Tools
If it is a list, select or iterate its elements
A list uses integer positions, not field names. If it contains dictionaries, iterate the list so each loop variable is a dictionary:
rows = [{"name": "Ada"}, {"name": "Bo"}]
for row in rows:
print(row["name"])
You can also select a particular element with an integer index, such as rows[0]["name"], if that is what the program needs.
If it is a dictionary, check what the loop variable contains
Iterating over a dictionary directly yields its keys. If each loop variable is expected to be a record, it may instead be a string key. Iterate over the values or key-value pairs according to the task:
users = {"u1": {"name": "Ada"}, "u2": {"name": "Bo"}}
for user in users.values():
print(user["name"])
Use .items() when both the key and its corresponding value are needed:
PC Slower Than It Used to Be?
A free scan shows the junk files, broken settings and background clutter dragging Windows down - then fixes them in one click.Free scan · Windows 10 & 11Crashes, No Sound, or Screen Glitches?
Random freezes, missing sound and display glitches usually trace back to one bad driver. Find and replace yours safely.Free scan · under a minuteBest Value
for user_id, user in users.items():
print(user_id, user["name"])
If it really is text, use a character position
When the value is intended to remain text, access a character with an integer position or a range with a slice—for example, text[0] or text[:5]. If the goal is to find or transform text, use the relevant string operation rather than treating it as a mapping.
Check for the JSON shape your code expects
If decoding JSON produces a string, the JSON value itself may be a string. For example, a JSON document can contain a quoted string rather than an object with named fields. Another possibility is that a producer encoded JSON text as a JSON string. Inspect the decoded value and the producer’s expected schema before decoding again; repeated decoding is not a general fix.
Do not use eval() to parse JSON. Use Python’s JSON decoder. Malformed JSON raises a decoding error; that is distinct from this TypeError, which occurs when code applies an unsuitable index to an object.
Tell similar errors apart
KeyError: The object is a mapping, but the requested key is absent.JSONDecodeError: The supplied text is not valid JSON for the decoder.list indices must be integers or slices, not str: The object being indexed is a list, and the code supplied a string index.
In each case, inspect the traceback expression and the runtime object to identify whether the issue is the container type, the index, or the input format.
Quick wins for a faster PC:
Clear out junk files and repair common Windows errorsFree Scan →Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Why the error message may vary
The core behavior is covered by the Python 3.14.8 documentation. Wording can vary by Python version: the error guide notes that Python 3.11 and later may include the offending type in a message such as not 'str'. That wording change does not mean the underlying indexing rule changed.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




