You should pass the file contents (i.e. a string) to json.loads(), not the file object itself. Try this:

with open(file_path) as f:
    data = json.loads(f.read())
    print(data[0]['text'])

There's also the json.load() function which accepts a file object and does the f.read() part for you under the hood.

Answer from Eugene Yarmash on Stack Overflow
🌐
Reddit
reddit.com › r/learnpython › tough time parsing json files, i receive an iowrapper object rather than string.
r/learnpython on Reddit: Tough time parsing JSON files, I receive an IOWrapper object rather than string.
December 28, 2017 - Note that there is a very big difference between json.dump()/json.load() and json.dumps()/json.loads(). Make sure to check out this section of the docs for more details. ... Thank you so much. Just read the docs. Looks like i needs dumps() and loads(). Is it still correct to wrap the dict I receive in a str? EDIT: When using loads and dumps OR load and dump, I receive: TypeError: Object of type 'TextIOWrapper' is not JSON serializable
Problem parsing Json file Aug 8, 2019
r/Python
6y ago
Using Python to Parse a JSON Object Mar 6, 2026
r/PythonLearning
4mo ago
JSON Serialization Mar 15, 2024
r/Python
2y ago
Trouble with the use of json module Feb 25, 2026
r/learnpython
4mo ago
Elegant Method in python to work with Json Files ? Oct 11, 2025
r/learnpython
9mo ago
More results from reddit.com
🌐
GitHub
github.com › RDFLib › rdflib-jsonld › issues › 55
Error reading JSON from text IO stream under Python 3 · Issue #55 · RDFLib/rdflib-jsonld
August 24, 2018 - def source_to_json(source): # TODO: conneg for JSON (fix support in rdflib's URLInputSource!) source = create_input_source(source, format='json-ld') stream = source.getByteStream() try: if PY3: if isinstance(stream, TextIOBase): use_stream = stream else: use_stream = TextIOWrapper(stream, encoding='utf-8') return json.load(use_stream) # json_data = stream.read() # if isinstance(json_data, bytes): # json_data = json_data.decode('utf-8') # return json.loads(json_data) # return json.load(StringIO(json_data)) # return json.load(StringIO(stream.read().decode('utf-8'))) else: return json.load(stream) finally: stream.close()
Author   RDFLib
🌐
Moonbooks
moonbooks.org › Articles › How-to-read-a-JSON-file-using-python-
How to read a JSON file using python ?
August 25, 2022 - with open('data.json') as json_data: print(type(json_data)) returns · <class '_io.TextIOWrapper'> To stock the JSON data in a python dictionary, a solution is to use load() from the json module, example: import json with open('data.json') as json_data: data_dict = json.load(json_data) ...
🌐
Reddit
reddit.com › r/learnpython › typeerror: '_io.textiowrapper'
r/learnpython on Reddit: TypeError: '_io.TextIOWrapper'
November 28, 2022 -

I'm supposed to create a dictionary from the values in a file and search for 'Polly' and remove it if it's in the file,

I kept getting errors so I'm just trying to get it to print the value just so I can see what I'm doing wrong and even at the most simple level I keep getting errors,

I'm in my first semester so this is all still new to me

employees = {}
employees = open('dictionary_values.txt', 'r')
print(employees['Polly'])

Traceback (most recent call last):
  File "main.py", line 3, in <module>
    print(employees['Polly'])
TypeError: '_io.TextIOWrapper' object is not subscriptable

🌐
Researchdatapod
researchdatapod.com › home › how to solve python typeerror: the json object must be str, bytes or bytearray, not ‘textiowrapper’
How to Solve Python TypeError: the JSON object must be str, bytes or bytearray, not 'TextIOWrapper' - The Research Scientist Pod
September 18, 2024 - TextIOWrapper is the file object returned when the open() function opens a file. The _io.TextIOWrapper class provides methods and attributes to help us read and write data to and from the file.
🌐
ProgramCreek
programcreek.com › python › example › 5779 › io.TextIOWrapper
Python Examples of io.TextIOWrapper
def request_list( self, identity: Identity ) -> Iterator[Sequence[Mapping[str, object]]]: team = self.team if not (isinstance(team, identity.team_type) and cast(str, identity.identifier).startswith(team.server_url)): return start = 0 while True: response = self.request( identity, 'GET', self.LIST_URL.format(self.team, start) ) assert response.code == 200 payload = json.load(io.TextIOWrapper(response, encoding='utf-8')) response.close() yield from payload['values'] if payload['isLastPage']: break start = payload['nextPageStart'] ... def toprettyxml(self, indent="\t", newl="\n", encoding=None):
Find elsewhere
🌐
Codecademy
codecademy.com › learn › dacp-python-fundamentals › modules › dscp-python-files › cheatsheet
Python Fundamentals: Python Files Cheatsheet | Codecademy
Every subsequent .readline() will extract the next line in the file if it exists. with open('story.txt') as story_object: print(story_object.readline()) will print only the first line in story.txt. JSON format is used to store key value pairs.
🌐
NetworkLessons.com
forum.networklessons.com › lessons discussion
Python JSON - Lessons Discussion - NetworkLessons.com Community Forum
April 20, 2020 - This lesson explains how to work with the JSON data format in Python. We'll see how to convert JSON strings to dictionaries, vice versa, and more · How can I select the “routers” label · When you want to “select” a certain field in a JSON (or dictionary), it’s best to use an IDE ...
🌐
Python Morsels
pythonmorsels.com › TextIOWrapper
TextIOWrapper‽ converting files to strings in Python - Python Morsels
February 5, 2024 - Ever encountered a TextIOWrapper object in Python when you really wanted a string? Converting an _io.TextIOWrapper object to a string is fortunately pretty easy: call the read method!
🌐
Python
docs.python.org › 3 › library › io.html
io — Core tools for working with streams
TextIOWrapper, which extends TextIOBase, is a buffered text interface to a buffered raw stream (BufferedIOBase). Finally, StringIO is an in-memory stream for text. Argument names are not part of the specification, and only the arguments of open() ...
🌐
Prodigy
support.prodi.gy › t › getting-io-textiowrapper-instead-of-string-when-using-patterns › 893
Getting io.TextIOWrapper instead of string when using --patterns - usage - Prodigy Support
October 17, 2018 - Hi, I created a custom Elastic Search loader. When I’m using it with single keyword like that: prodigy elastic.textcat.teach my_dataset en_core_web_sm "bank account number" --label SENSITIVE` it works just fine. However, when I’m trying to load a list of terms it fails: prodigy elastic.textcat.teach my_dataset en_core_web_sm --patterns terms/sensitive_terms.json --label SENSITIVE The reason is my loader function gets io.TextIOWrapper instead of str.