The JSON object you have is a list of dictionaries (one at least), so you simply need to grab the first element of the list.

d = a[0]
d['text']
Answer from Kyle James Walker on Stack Overflow
🌐
Reddit
reddit.com › r/learnpython › convert json list to dictionary
r/learnpython on Reddit: convert JSON list to dictionary
January 13, 2024 -

I must first preface this with the fact that I’m extremely new to python. Like just started learning it a little over a week ago.
I have been racking my brain over how to convert a json object I opened and loaded into a dictionary from a list so I can use the get() function nested within a for loop to do a student ID comparison from another json file (key name in that file is just ID).
Below is the command I’m trying to load the json file:
With open(‘file.json’) as x: object=json.load(x)
When I print(type(object)), it shows up as class list.
Here’s a sample of what the json looks like:
[

{

“Name”: “Steel”,

“StudentID”: 3458274

“Tuition”: 24.99

},

{

“Name”: “Joe”,

“StudentID”: 5927592

“Tuition”: 14.99

}

]
HELP! Thank you!

Discussions

Python: converting a list of dictionaries to json - Stack Overflow
I thought it was only supposed to be used for dicts. 2014-02-03T10:54:20.563Z+00:00 ... Is it possible to save the file as JSON Column Array or JSON row Array? 2016-04-21T16:13:15.47Z+00:00 ... NOTE: re-assigning list (list=[1,2,3]) conflicts with the builtin method list(). please keep in mind. 2020-09-19T22:23:44.557Z+00:00 ... I want to remove outer arrays, @markcial. Can you please help? 2021-09-15T20:08:30.707Z+00:00 ... reply to @Abdul Haseeb take a look at docs.python... More on stackoverflow.com
🌐 stackoverflow.com
How to convert Python dict to JSON as a list, if possible - Stack Overflow
I want my JSON serializations to match for both my PHP and Python code. Unfortunately, changing the PHP code isn't an option in my case. Any suggestions? The only solution I have found is to write my own function to go through and verify each python dictionary and see if it can first be converted to a list ... More on stackoverflow.com
🌐 stackoverflow.com
May 31, 2024
Python: JSON string to list of dictionaries - Getting error when iterating - Stack Overflow
I am sending a JSON string from Objective-C to Python. Then I want to break contents of the string into a Python list. I am trying to iterate over a string (any string for now): import json s = ... More on stackoverflow.com
🌐 stackoverflow.com
July 23, 2025
convert list of dictionary to list of json objects
Json.dumps will convert the dictionary to a string but the string is valid JSON. You see the single quotes since Python is indicating this is a string (and double quotes is being used internally). More on reddit.com
🌐 r/learnpython
7
2
October 13, 2022
🌐
Python Examples
pythonexamples.org › python-json-to-dict
Python JSON to Dictionary
3 weeks ago - To convert Python JSON string to Dictionary, use json.loads() function. Note that only if the JSON content is a JSON Object, and when parsed using loads() function, we get Python Dictionary object. JSON content with array of objects will be converted to a Python list by loads() function.
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-convert-list-of-dictionaries-to-json
Python - Convert list of dictionaries to JSON - GeeksforGeeks
July 5, 2025 - json.dump() saves the list of dictionaries to output.json, converting tuples to lists using the default parameter.
Find elsewhere
🌐
W3Schools
w3schools.com › python › python_json.asp
Python JSON
Convert from Python to JSON: import json # a Python object (dict): x = { "name": "John", "age": 30, "city": "New York" } # convert into JSON: y = json.dumps(x) # the result is a JSON string: print(y) Try it Yourself » · You can convert Python objects of the following types, into JSON strings: dict · list ·
🌐
GeeksforGeeks
geeksforgeeks.org › python › convert-json-to-dictionary-in-python
Convert JSON to dictionary in Python - GeeksforGeeks
July 12, 2025 - Create a json string and store it in a variable 'json_string' after that we will convert the json string into dictionary by passing 'json_string' into json.loads() as argument and store the converted dictionary in 'json_dict'.
🌐
Pythonspot
pythonspot.com › json-encoding-and-decoding-with-python
python json - Python Tutorial
Convert JSON to Python Object (float) ... of how to use that below: Convert Python Object (Dict) to JSON If you want to convert a Python Object to JSON use the json.dumps() method....
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-json-to-list
Python Json To List - GeeksforGeeks
April 27, 2022 - 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 `array`. The `print` statements display the type of the original string, the first element of the resulting list, and the type of the converted list, respectively.
🌐
Heardlibrary
heardlibrary.github.io › digital-scholarship › script › python › json
Dictionaries and JSON | Digital Education Resources - Vanderbilt Libraries Digital Lab
May 31, 2024 - A “JSON array” is very similar to a Python list. In the same way that JSON objects can be nested within arrays or arrays nested within objects, Python dictionaries can be nested within lists or lists nested within dictionaries. So pretty much any JSON data structure can be translated into a complex Python data object. There is a Python library, appropriately called the json module, that will convert ...
Top answer
1 of 6
365

Your JSON is an array with a single object inside, so when you read it in you get a list with a dictionary inside. You can access your dictionary by accessing item 0 in the list, as shown below:

json1_data = json.loads(json1_str)[0]

Now you can access the data stored in datapoints just as you were expecting:

datapoints = json1_data['datapoints']

I have one more question if anyone can bite: I am trying to take the average of the first elements in these datapoints(i.e. datapoints[0][0]). Just to list them, I tried doing datapoints[0:5][0] but all I get is the first datapoint with both elements as opposed to wanting to get the first 5 datapoints containing only the first element. Is there a way to do this?

datapoints[0:5][0] doesn't do what you're expecting. datapoints[0:5] returns a new list slice containing just the first 5 elements, and then adding [0] on the end of it will take just the first element from that resulting list slice. What you need to use to get the result you want is a list comprehension:

[p[0] for p in datapoints[0:5]]

Here's a simple way to calculate the mean:

sum(p[0] for p in datapoints[0:5])/5. # Result is 35.8

If you're willing to install NumPy, then it's even easier:

import numpy
json1_file = open('json1')
json1_str = json1_file.read()
json1_data = json.loads(json1_str)[0]
datapoints = numpy.array(json1_data['datapoints'])
avg = datapoints[0:5,0].mean()
# avg is now 35.8

Using the , operator with the slicing syntax for NumPy's arrays has the behavior you were originally expecting with the list slices.

2 of 6
31

Here is a simple snippet that read's in a json text file from a dictionary. Note that your json file must follow the json standard, so it has to have " double quotes rather then ' single quotes.

Your JSON dump.txt File:

{"test":"1", "test2":123}

Python Script:

import json
with open('/your/path/to/a/dict/dump.txt') as handle:
    dictdump = json.loads(handle.read())
🌐
iO Flood
ioflood.com › blog › python-dict-to-json
Convert a Python Dict to JSON | json.dumps() User Guide
March 20, 2024 - In this code, we try to convert a Python dictionary containing a set to JSON using json.dumps(). However, since sets are not JSON serializable, we encounter a TypeError. One way to handle this issue is to convert the set to a list before serializing it. Lists, unlike sets, are JSON serializable.
🌐
Spark By {Examples}
sparkbyexamples.com › home › python › convert json to dictionary in python
Convert JSON to Dictionary in Python - Spark By {Examples}
May 31, 2024 - Let’s discuss how to convert the JSON string object to a Dictionary in python. From JSON string, we can convert it to a dictionary using the json.loads() method. Suppose you have a JSON file, then loads() will not work.
🌐
Finxter
blog.finxter.com › home › learn python blog › 5 best ways to read a json file into a list of dictionaries in python
5 Best Ways to Read a JSON File into a List of Dictionaries in Python - Be on the Right Side of Change
February 22, 2024 - import json # Assume 'data_lines.json' contains one JSON object per line. with open('data_lines.json', 'r') as file: list_of_dicts = [json.loads(line) for line in file] print(list_of_dicts) ...
🌐
Python.org
discuss.python.org › python help
Issue converting list of dicts into string using json.dumps - Python Help - Discussions on Python.org
May 14, 2021 - I have list with dictionary of objects and want to convert the list into string. i tried json.dumps(transactions, sort_key=True) and it just returns though the list is not empty and I can iterate the list and print the…
🌐
Reddit
reddit.com › r/learnpython › convert json array to dictionary
r/learnpython on Reddit: Convert JSON array to Dictionary
March 22, 2022 -

I have a JSON array file that I want to convert to a dictionary. The file has only one pair of square brackets [] with a dictionary of sub dictionaries inside it. print(len(dict)) returns 14. I want to simply convert the file to a dict but using json.loads() creates a list and using json.loads(filename)[0] to get that sole large item of nested dictionaries inside the json array only returns the first dictionary object and not the entire 14.

I want to know if there’s another way of doing this besides a dictionary comprehension which I found, but don’t necessarily understand. Thanks.