0

I have my dict as follows

user_model = {
    "users": [{
            "userid": 100,
            "level": 1,
            "score": 5,
        },
        {
            "userid": 101,
            "level": 2,
            "score": 5,
        },
        {
            "userid": 100,
            "level": 2,
            "score": 5,
        },
        {
            "userid": 103,
            "level": 1,
            "score": 2,
        }
    ]
}

Can someone please point me in right direction to update only "score" if my "userid" is 103 and "level" is 2.

Thanks

EngineerAkki
  • 89
  • 1
  • 9

1 Answers1

1

This way you can list all the data in your json:

for item in user_model['users']:
    print(item) #check items
    if item['userid'] == 103:
        item['score'] = 25
        print(item)
Joaquín
  • 350
  • 2
  • 12