Just do a simple .keys()

>>> dct = {
...     "1": "a", 
...     "3": "b", 
...     "8": {
...         "12": "c", 
...         "25": "d"
...     }
... }
>>> 
>>> dct.keys()
['1', '8', '3']
>>> for key in dct.keys(): print key
...
1
8
3
>>>

If you need a sorted list:

keylist = dct.keys() # this is of type `dict_key`, NOT a `list`
keylist.sort()

And if you want them as simple list, do this:

list(dct_instance.keys())
Answer from karthikr on Stack Overflow
๐ŸŒ
DEV Community
dev.to โ€บ bluepaperbirds โ€บ get-all-keys-and-values-from-json-object-in-python-1b2d
Get all keys and values from json object in Python - DEV Community
January 12, 2021 - Using load function json file, this let me keep it into a variable called data. ... Then you have a Python object. Now you can get the keys and values. The code below depends on what your json file looks like.
๐ŸŒ
Like Geeks
likegeeks.com โ€บ home โ€บ python โ€บ how to get json value by key in python
How To Get JSON Value by Key in Python
By converting the JSON string to a Python dictionary using json.loads(), you can retrieve any value by simply referencing its key. Using the get() method to access values provides a safer alternative to direct key access.
๐ŸŒ
Reddit
reddit.com โ€บ r/learnpython โ€บ list all json keys in a file to identify database column names from a file using python
r/learnpython on Reddit: List all JSON keys in a file to identify database column names from a file using Python
July 9, 2022 -

I am learning Python, and in particular, working with JSON and sqlite in Python. Ultimately I plan to use Python to load the JSON into a sqlite database.

Here is the question: Is there a way in to list all of the keys from a JSON file (not from a string) using Python? I want a list of all of the keys so I can determine what columns I will need/use in my sqlite table(s), without having to manually read the file and make a list.

BTW, this is something along the lines of using INFORMATION_SCHEMA.COLUMNS in SQL Server, or the FINDALL in Python for XML.

All of this is for personal learning, so I'm not looking to use other technologies, I'm sticking to Python, JSON, and sqlite on purpose.

๐ŸŒ
Medium
medium.com โ€บ @sharath.ravi โ€บ python-function-to-extract-specific-key-value-pair-from-json-data-7c063ecb5a15
Python function to extract specific key value pair from json data. | by Sharath Ravi | Medium
April 6, 2023 - import json def extract_key_va... example, the function extract_key_value takes two arguments: json_data, which is a string containing JSON data, and key, which is the key for the value that you want to extract....
๐ŸŒ
LabEx
labex.io โ€บ tutorials โ€บ python-how-to-access-nested-keys-in-a-python-json-object-395034
How to access nested keys in a Python JSON object | LabEx
Full JSON structure: { "name": ... When working with nested JSON structures, you can access nested elements by chaining keys with square brackets:...
๐ŸŒ
Plain English
plainenglish.io โ€บ blog โ€บ extracting-specific-keys-values-from-a-messed-up-json-file-python-dfb671482681
Extracting Specific Keys/Values From A Messed-Up JSON File (Python)
We first initialize out as an empty list, and queue to contain our entire json data. remove the first element from the queue, and assign it to current ยท If current is a dictionary, search it for the keys that we want, and add any found key-value pairs into out.
Find elsewhere
๐ŸŒ
YouTube
youtube.com โ€บ watch
Get All Keys and Values from Json Object Python - YouTube
Get All keys from json object using python using json.getKeys() similarly we can get all values from json object .#JsonParsingPython,#GetAllKeysJsonPython,#G...
Published ย  December 15, 2020
๐ŸŒ
PYnative
pynative.com โ€บ home โ€บ python โ€บ json โ€บ python check if key exists in json and iterate the json array
Python Check if key exists in JSON and iterate the JSON array
May 14, 2021 - Check if the key exists or not in JSON using Python. Check if there is a value for a key. Return default value if the key is missing in JSON. Iterate JSON array in Python.
๐ŸŒ
Python Forum
python-forum.io โ€บ thread-37297.html
Trying to parse only 3 key values from json file
So im playing around with parsing a json file in python. Im able to read in the file and print it to the console, but now i want to extract 3 values from each 'section' not sure what the proper terminology is. Here is a example of the data structure...
๐ŸŒ
Quora
quora.com โ€บ How-do-you-get-all-values-by-key-with-JSON-and-Python
How to get all values by key with JSON and Python - Quora
Answer: You can use the [code ]json[/code] library in Python to get values associated with a key in a JSON object. Here's an example: [code]import json # sample JSON data data = """ { "employees": [ { "firstName": "John", "lastName": "Doe" }, ...
๐ŸŒ
Python.org
discuss.python.org โ€บ python help
How to get Json keys as columns in a csv with python? - Python Help - Discussions on Python.org
September 17, 2023 - I am getting JSON-Data from the AzureDevOps-API and I want to save the data in a csv-file with the JSON-Keys as column-names. I have the following code: import requests import pandas api_url = "***" Headers = { "Authorization" : "***" } response = requests.get(api_url, headers=Headers) obj = pandas.read_json(response.text, orient='values') obj.to_csv('output1.csv') I am getting the following csv-output: So the JSON-Keys are not the column names and everything is in Column A nothing in Co...
๐ŸŒ
W3Schools
w3schools.com โ€บ python โ€บ python_json.asp
Python JSON
The json.dumps() method has parameters to make it easier to read the result: Use the indent parameter to define the numbers of indents: ... You can also define the separators, default value is (", ", ": "), which means using a comma and a space ...
๐ŸŒ
GitHub
gist.github.com โ€บ koddr โ€บ 1335333ef927a8ac1cd6274aea7d25c3
Python: JSON only get keys in first level ยท GitHub
Python: JSON only get keys in first level. GitHub Gist: instantly share code, notes, and snippets.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ python-program-to-extract-a-single-value-from-json-response
Python program to extract a single value from JSON response - GeeksforGeeks
July 23, 2025 - Import JSON from the modules. Open the JSON file in read-only mode using the Python with() function. Load the JSON data into a variable using the Python load() function. Now, get the value of keys in a variable.
๐ŸŒ
Robotastemtraining
robotastemtraining.com โ€บ read โ€บ how-do-you-get-all-values-by-key-with-json-and-python
How Do You Get All Values by Key with JSON and Python?
import json # Load JSON data json_data = ''' { "name": "John", "age": 30, "city": "New York", "children": [ { "name": "Anna", "age": 10 }, { "name": "Alex", "age": 7 } ] } ''' data = json.loads(json_data) # Function to get all values by key def get_values_by_key(data, key): values = [] def extract(data, values, key): if isinstance(data, dict): for k, v in data.items(): if k == key: values.append(v) extract(v, values, key) elif isinstance(data, list): for item in data: extract(item, values, key) extract(data, values, key) return values # Extract values key_to_extract = 'name' values = get_values_by_key(data, key_to_extract) print(values) Extracting all values associated with a specific key from a JSON object in Python is straightforward with the right approach.
๐ŸŒ
Reddit
reddit.com โ€บ r/pythonhelp โ€บ json get value by keys path (string)
r/pythonhelp on Reddit: JSON get value by keys path (string)
March 26, 2022 -

I have a JSON file that I want to automatically check specific values, like myJSON['generic']['lessgeneric']['store'] should be equal to 100,

was thinking of doing something like this:

checks = [ {'name':'field_1','path':'myJSON['generic']['lessgeneric']['store']','value':'100'} ]

but I have no clue how to convert the string "myJSON['generic']['lessgeneric']['store']" into it's value, any help would be appreciated!

edit: how I solved it

path = "generic>lessgeneric>store"
value = 100
def check_value(path,value):
    temp_json = my_json
    for key in path.split(">"):
        temp_json = temp_json[key]
    if temp_json == value:
        pass