I have an json array that looks like this:
{
"inventory": [
{
"Name": "katt"
},
{
"Name": "dog"
}
]
}
And now I want to access this array in a program that I'm creating and remove a element, for example "Name": "dog". I'm not super familiar with how to work with json in python, but so far I have tried something like this:
import json
jsonfile = open("viktor.json", "r")
jsonObj = json.load(jsonfile)
jsonfile.close()
counter = 0
for item in range(len(jsonObj["inventory"])):
print(jsonObj["inventory"][counter])
print(type(jsonObj["inventory"][counter]))
if jsonObj["inventory"][counter] == argOne:
print("hej")
counter += 1
So first I read from the json and stores the data in a variable. Then I want to loop through the whole variable and see if I can find any match, and if so, I want to remove it. I think I can use a pop() method here or something? But I can't seem to get my if-statement to work properly since the jsonObj["inventory"][counter] is a dict and argOne is a string.
What can I do instead of this? Or what I'm missing?