I'm working on a Python Pygame project were I have to work with JSON files. I'm trying to read a JSON file, but I just can't get it to print what I want to know.
This is the JSON file:
{
"pokemons": {
"5": {
"name": "Snivy",
"type": "Grass",
"hp": 45,
"attack": 45,
"defence": 55,
"speed": 63,
"moves": [
"Tackle",
"Leer",
"null",
"null"
],
"level": 4,
"xp": 54
},
"2": {
"name": "Tepig",
"type": "Fire",
"hp": 65,
"attack": 63,
"defence": 45,
"speed": 45,
"moves": [
"Tackle",
"Tail Whip",
"Ember",
"null"
],
"level": 7,
"xp": 11
}
}
}
I'm trying to read the "name", "type", etc from the different "ID's" aka "5" and "2", but I can only make it print "5" and "2" from the "pokemons" array
with open("data.json", "r") as f:
data = json.load(f)
for i in data["pokemons"]:
print(i)
for k,v in data['pokemonds'].items(): print (k, v)