parsing a large json file and retrieving values in python
<p>I have one large json file of the format - </p>

<pre><code>{
    "x": "",
    "y": {
        "a": {
            "-3": {
                "id": -2,
                "rut": "abc",

            },
            "-1": {
                "id": -1,
                 "rut": "cdf",

             } 
        }
     }
}
</code></pre>

<p>Now I want to retrieve the values of <code>id</code> for all situations.
For this I have the following code -</p>

<pre><code>import json
from pprint import pprint

with open('file.json') as data_file:
data = json.load(data_file)
data['y']['a'].value()['id']
</code></pre>

<p>Since I'm not too familiar with using json in python, I couldn't figure out what I was doing wrong. I used <code>.value()</code> because the values <code>-3</code> and <code>-1</code> could be <b> any number </b> and are not known before hand. The rest of the values are constant. </p>

<p>Did you mean to use values() ?</p>

<p>However, to get the all 'id's:</p>

<pre><code>sub_data = data['y']['a']
for i in sub_data:
    print(sub_data['id'])
</code></pre>

python json