You're trying to read the string "data.txt". What you want is to open and read the file.

import json

with open('data.txt', 'r') as data_file:
    json_data = data_file.read()

data = json.loads(json_data)
Answer from Agustín Lado on Stack Overflow
🌐
W3Schools
w3schools.com › python › python_json.asp
Python JSON
import json # some JSON: x = '{ "name":"John", "age":30, "city":"New York"}' # parse x: y = json.loads(x) # the result is a Python dictionary: print(y["age"]) Try it Yourself »
🌐
GeeksforGeeks
geeksforgeeks.org › python › json-loads-in-python
json.loads() in Python - GeeksforGeeks
Explanation: json.loads(s) converts the JSON array into a Python list.
Published: January 13, 2026
🌐
PYnative
pynative.com › home › python › json › python json parsing using json.load() and loads()
Python JSON Parsing using json.load() and loads()
May 14, 2021 - Understand use of json.loads() and load() to parse JSON. Read JSON encoded data from a file or string and convert it into Python dict
🌐
Python Examples
pythonexamples.org › python-json-to-list
Python JSON to List
Python JSON to List - To convert a JSON String to Python List, use json.loads() function. loads() function takes JSON Array string as argument and returns a Python List. In this tutorial, we have examples to load json array string to python list.
🌐
Real Python
realpython.com › python-json
Working With JSON Data in Python – Real Python
August 20, 2025 - json.loads(): To deserialize a string, bytes, or byte array instances
🌐
Delft Stack
delftstack.com › home › howto › python › parse json array of objects in python
How to Parse JSON Array of Objects in Python | Delft Stack
February 2, 2024 - The JSON data string is parsed by the json.loads() function, which then provides a Python dictionary with all of the data from the JSON.
🌐
Python
docs.python.org › 3 › library › json.html
JSON encoder and decoder — Python 3.14.7 documentation
Identical to load(), but instead of a file-like object, deserialize s (a str, bytes or bytearray instance containing a JSON document) to a Python object using this conversion table.
🌐
py4u
py4u.org › blog › python-read-in-an-array-of-json-objects-using-json-loads
How to Read an Array of JSON Objects from a File in Python Using json.loads() – Fixing Common Errors
Objects within the array follow JSON object rules (key-value pairs with double quotes for keys). The json module in Python provides two primary methods for parsing JSON: json.load(file_object): Parses JSON directly from a file-like object (e.g., ...
Find elsewhere
🌐
Processing
processing.org › reference › loadJSONArray_.html
loadJSONArray() / Reference
January 1, 2021 - Loads an array of JSON objects from the data folder or a URL, and returns a JSONArray. Per standard JSON syntax, the array must be enclosed in a pair of hard brackets [], and each object within the array must be separated by a comma.
🌐
Reddit
reddit.com › r/learnpython › extremely confused with parsing a json array
r/learnpython on Reddit: Extremely confused with parsing a JSON array
April 14, 2017 -

Hi everyone. I'm really, really confused about parsing a JSON array.

For my script, I'll need to use a reverse geocoder, and I've decided to use Google's. I'm requesting a JSON, and it's returning this: https://developers.google.com/maps/documentation/geocoding/intro#reverse-example.

What I can't seem to figure out is the proper way of parsing it. I'm trying to extract the long_name in a few different types (for this example, let's say route, neighborhood, and administrative_area_level_2), and pass each long name for each type as their own string.

I'm completely lost on how to go about parsing this. I've tried json.loads, and doing a bunch of other things that fail in a "list indices must be integer", or unexpected results.

Right now, this is the nieve code I'm using to at least print long_name (about 30 times):

reverse_json = json.load(reader(reverseJSON))
# Excuse the debugging
print(reverse_json) 

for data in reverse_json['results']:
    address = data['address_components']
    for data in address:
        address = data['long_name']
        print(address)

And if I add on this to the final for loop:

if data['types'] == "['route']":
    address = data['long_name']
    print(address)

I get nothing.

json.loads doesn't help, either. It just results in

TypeError: the JSON object must be str, bytes or bytearray, not 'StreamReader'

So, I'm stuck with trying to parse a JSON array, and to have "long_name" become a certain variable if a certain type occurs. It's confusing to me, hopefully it isn't to you.

A simple explanation and help would be appreciated.

🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Learn_web_development › Core › Scripting › JSON
Working with JSON - Learn web development | MDN
2 weeks ago - If you load this JSON in your JavaScript program as a string, you can parse it into a normal object and then access the data inside it using the same dot/bracket notation we looked at in the JavaScript object basics article. For example: ... First, we have the variable name — superHeroes. Inside that, we want to access the members property, so we use .members. members contains an array populated by objects.
🌐
freeCodeCamp
freecodecamp.org › news › python-read-json-file-how-to-load-json-from-a-file-and-parse-dumps
Python Read JSON File – How to Load JSON from a File and Parse Dumps
October 27, 2020 - This is a variable that we can use within the with statement to refer to the file object. ... json.load(file) creates and returns a new Python dictionary with the key-value pairs in the JSON file.
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-json-to-list
Python Json To List - GeeksforGeeks
April 18, 2026 - In this example, the below code utilizes the json.loads() method to convert a JSON-formatted string [1,2,3,4] into a Python list named arr.
🌐
DataCamp
datacamp.com › tutorial › json-data-python
Python JSON Data: A Guide With Examples | DataCamp
December 3, 2024 - This option allows you to specify the separators used in the output JSON string. The separators parameter takes a tuple of two strings, where the first string is the separator between JSON object key-value pairs, and the second string is the separator between items in JSON arrays.
🌐
Qlik Community
community.qlik.com › t5 › Member-Articles › Parsing-JSON-Array-Homogeneous-Objects › ta-p › 2535153
Parsing: JSON Array (Homogeneous Objects) - Qlik Community - 2535153
November 4, 2025 - In the other articles it was easy for me to simply create an inline table that contained that JSON Block. But for an array we have a special issue to deal with ... those brackets the define the beginning and end of the array "[" "]" Those 2 characters are special and define the beginning and end of our inline statement and thus they cause a problem. Notice that I've simply duplicated the characters [[ and ]] in my line of code, so that the inline table reads it in, and then I do a preceding load to pull the duplicate brackets right back out.
🌐
Zyte
zyte.com › home › blog › json parsing with python [practical guide]
JSON Parsing with Python [Practical Guide]
December 3, 2024 - The json module provides two methods, loads and load, that allow you to parse JSON strings and JSON files, respectively, to convert JSON into Python objects such as lists and dictionaries.
🌐
Stack Overflow
stackoverflow.com › questions › 49457871 › json-loads-is-loading-an-array-of-json-objects-as-characters
python - json.loads is loading an array of json objects as characters - Stack Overflow
Are you turning your JSON string into a JSON string? (Which means the decoded result would be a string, not an array or object.) What exactly is line[11:-7] on its own? ... Save this answer. ... Show activity on this post. obj is still a JSON string. Decode it again with obj = json.loads(obj).