List KeyError Python
<p>I'm trying to append a list with values from an API for the Glassdoor.</p>

<p>When I get a response back from this API, I get info such as the name of the company, ratings, CEO, a bunch more info, and lastly if the company is owned by a parent company, I get that too.</p>

<p>My problem is when I append my list with all this info, if the company I'm getting a response from the API doesn't have a parent company, I don't want it to skip extracting the other relevant data like name, CEO, etc. I want it to print out the available data for that companies response, then where the parent company is print NA.</p>

<p>Each company I get a response from the API may have a different length/vary in the available data.</p>

<p>For example:</p>

<pre><code>comp_info.append(data['response']['employers'][0]['name'])
</code></pre>

<p>This is what I'm trying to achieve, Apple doesn't have a parent company, while LSI Corporation does. I'm not sure how to approach this problem?</p>

<p>[APPLE, Tim Cook, 4.5, N/A, Computer Hardware]
[LSI Corporation, Some Guy, 4.6, Avago Technologies, Computer Hardware]</p>

<pre><code>comp_info.append(data['response']['employers'][0].get('parentEmployer', 'N/A'))
</code></pre>

python json for-loop keyerror