Click here to Skip to main content
15,566,615 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a json file stored multiple libraries. Just want to know how should I get the value for a specific key from diff libraries. For example, each library contain info about a meal, and I want to get names for every meal(name as a key).

What I have tried:

recipe = []
with open('maryCooks_allergen=salt.json', 'r') as fh:
s =
recipe_dictionary = json.loads(s)

for i in recipe_dictionary:
for key,value in i.items():
Updated 28-Nov-20 22:37pm

1 solution

You need to itrate through the dictionary post loading the json and then go through it's items to extract key or value.

Try something like this:
import json

# print values v if those are needed
def print_keys(mapping):
    [print('key:',k) for k, v in mapping.items()]
# some JSON:
x = '{ "name":"John Doe", "age":30, "city":"New York"}'

# parse x:
y = json.loads(x)

# all it's keys

#key: name
#key: age
#key: city
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900