Extract a specific section of a string depending on an input
<p>I have a very large <code>.json</code> converted into a <code>string</code>, containing numerous cities/countries.</p>

<p>I'd like to extract the information of the city depending on the user's choice of country (<em>London is just an example</em>). </p>

<p>For example, if the <code>Country</code> the user <em>inputed</em> was: <code>UK</code>, the following information would be extracted from the string:</p>

<p>I'm not too sure on how I could possibly achieve this due to my inexperience, but am aware that it would require an if statement. My progress so far:</p>

<pre><code>Country = raw_input('Country: ')
if 'UK' in string:
    ???
</code></pre>

<p>You can try this. Might still want to consider some user input errors in your code. For example, str.strip() and capital sensitive.</p>

<pre><code>import json
input_country = raw_input('Please enter country:')
with open('London.json') as fp:
    london_json = fp.read()
    london = json.loads(london_json)
    for item in london["response"]["results"]:
        if item['country'] == input_country:
            print json.dumps(item, indent = 2)
</code></pre>

python json string python-2.7 wunderground