0

I am new to the JSON python lib.

I have this JSON file:

   {
        "usrdata": [
            {
                "user": "---/ LandiPlayz \\---#****",
                "money": 10
            },
            {
                "user": "Snubz#****",
                "money": 10
            }
        ]
    }

and I need to modify the "money" field of one of the users. There will be more added users, so I need to find which one it is by finding the users name. Is that possible, or should I do format the file differently.

Thanks in advance

4

1 Answer 1

2

You have to iterate over the user_infos, and when getting the good one, update the money

json_value =    {
        "usrdata": [
            {"user": "---/ LandiPlayz \\---#****","money": 10},
            {"user": "Snubz#****","money": 10}
        ]
    }
username = "Snubz#****"
new_money = 50

for user_info in json_value["usrdata"]:
    if user_info['user'] == username:
        user_info['money'] = new_money
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.