look for given in a json python

0

I have the following code

    with open('states.json') as f:
    data = json.load(f)

for state in data["jquery"]:
    if(argumentos[2] == state['version']):
        print(state['name'], state['version'] + "existe")
    else:
        print("nao tem")

when running the program in python

python programa.py jquery 3.3.1

it should look in json where jquery is written and check if it has the second parameter that is version 3.3.1

But in my code above it runs through all json giving me the following output

jquery 3.3.1 existe
nao tem

he is validating the 2 lines if he finds it should show success message otherwise he should show message that does not exist only that he shows me the 2 messages because in json the first block is true and the second is false in the output end I just want you to show me whether there is what I'm looking for or not.

My json

{
"jquery":[
    {
        "name": "jquery",
        "version": "3.3.1",
        "extension": "js",
        "caminho": "https://code.jquery.com/jquery-3.3.1.min.js"
    },
    {
        "name": "jquery",
        "version": "1.5.6",
        "extension": "js",
        "caminho": "https://code.jquery.com/jquery-1.5.6.min.js"
    }
],

"bootstrap":[
    {
        "name": "bootstrap",
        "version": "1.2.8",
        "caminho": "https://bootstrap.com.br"
    }
]
}

If anyone can give me a help thank you

    
asked by anonymous 23.05.2018 / 20:15

1 answer

2

I did a lot of similar to yours, the only difference is the definition of a variable for the control

It is set to False , if find will be set to True , then at the end it is only to check, if it does not find the searched content, the variable stays with the default value

with open('states.json') as f:
    data = json.load(f)

contem = False

for state in data["jquery"]:
    if (argumento[2] == state['version']):
        contem = True

if (contem):
    print(state['name'], state['version'] + "existe")
else:
    print("nao tem")
    
23.05.2018 / 21:34