Access JSON Key in Python
<p>I'm trying to print out all the <code>cpe_mac</code> fields of my JSON data.</p>

<h1>I have</h1>

<pre><code># Last updated : BH | 8/31/2016

import requests
import json

ssc_ip = raw_input("What is your SSC Host (Ex. http://172.19.242.32:1234/ ) ? : ")
if not ssc_ip:
    ssc_ip = 'http://172.19.242.32:1234/'

cpe_num = raw_input("How many CPE(s) you want to delete ? : ")
print '\n'

url = ssc_ip+'vse/vcpes'
json_data = requests.get(url).json()
# print json_data

for x in json_data:
    print json_data.cpe_mac
</code></pre>

<hr>

<p>I kept getting </p>

<p><code>AttributeError: 'dict' object has no attribute 'cpe_mac'</code></p>

<hr>

<h1>Trying</h1>

<p><code>print json_data['cpe_mac']</code></p>

<p>I got </p>

<p><code>KeyError: 'cpe_mac'</code></p>

<p>You have a nested dictionary, it should be:</p>

<pre><code>for x in json_data['data']:
    print x['cpe_mac']
</code></pre>

python