Parse JSON find value and append random number?
<p>I have a JSON file with login and integer valuer (some result), like this:</p>

<pre><code>[
        {
           "name":"Tamara",
           "results":"434.545.234.664"
        },
        {
           "name":"Ted",
           "results":"434.545.234.664"
        }
]
</code></pre>

<p>I need to receive user login (name), find inserted name in JSON. If it already exists, add some number to the "results". </p>

<p>For example: If I input "Ted", some number will be appended to Ted's results like this: <code>"results":"434.545.234.664+4343}"</code></p>

<p>If name doesn't exist, add new record with:</p>

<pre><code>{
    "name":"new_name",
    "results":"some_number"
}
</code></pre>

<p>in it.</p>

<p>My code, which didn't work: </p>

<pre><code>with open('/Users/users_db.json') as jsonfile:
    user_name = ''
    while user_name == '':
        data = json.load(jsonfile)
        user_name = input('Your name: ')
        for user in data:
            if user_name in user['name']:
                print('Old user')
                break
            else:
                print('New user')
</code></pre>

<p>You can <a href="https://docs.python.org/3.5/library/json.html" rel="nofollow">parse your json</a> like this</p>

<pre><code>import json

with open('yourJsonFile.json') as example_data:
    data = json.load(example_data)
</code></pre>

<p>And now it's a matter of working with <code>data</code> to find whatever you need. For example, to access the first name you could do</p>

<pre><code>data[0]['name']
</code></pre>

<p>The rest depends on where/how you store the names and check if they already exist.</p>

<p>Finally, to add a new value you can use <code>append</code></p>

python json input