title: Python accessing data in JSON object
body: <p>so I do this in my script:</p>
  
  <pre><code>import json
  info = json.loads(get_info())
  print info
  </code></pre>
  
  <p>Which outputs:</p>
  
  <pre><code>richard@richard-desktop:~/projects/hello-python$ python main.py 
  {
      "streams": [
          {
              "index": 0,
              "codec_name": "mpeg2video",
              "codec_long_name": "MPEG-2 video",
              "codec_type": "video",
              "codec_time_base": "1001/48000",
              "codec_tag_string": "[0][0][0][0]",
              "codec_tag": "0x0000",
              "width": 1920,
              "height": 1080,
              "has_b_frames": 1,
              "sample_aspect_ratio": "1:1",
              "display_aspect_ratio": "16:9",
              "pix_fmt": "yuv422p",
              "level": 2,
              "timecode": "00:59:59:00",
              "id": "0x1e0",
              "r_frame_rate": "24000/1001",
              "avg_frame_rate": "10000/417",
              "time_base": "1/90000",
              "start_time": "0.945411"
          },
          {
              "index": 1,
              "codec_name": "pcm_dvd",
              "codec_long_name": "PCM signed 20|24-bit big-endian",
              "codec_type": "audio",
              "codec_time_base": "1/48000",
              "codec_tag_string": "[0][0][0][0]",
              "codec_tag": "0x0000",
              "sample_fmt": "s32",
              "sample_rate": "48000",
              "channels": 2,
              "bits_per_sample": 0,
              "id": "0xa0",
              "r_frame_rate": "0/0",
              "avg_frame_rate": "0/0",
              "time_base": "1/90000",
              "start_time": "0.945411",
              "duration": "600.595000"
          }
      ],
      "format": {
          "filename": "/home/richard/projects/hello-python/tests/test_1.mpg",
          "nb_streams": 2,
          "format_name": "mpeg",
          "format_long_name": "MPEG-PS format",
          "start_time": "0.945411",
          "duration": "600.595000",
          "size": "4033241092",
          "bit_rate": "53723272"
      }
  }
  </code></pre>
  
  <p>How can I access streams or format and then properties inside them? For example how to get codec_long_name from the second stream or how to get duration from format?</p>
  
  <p>I tried:</p>
  
  <pre><code>print info[0]
  </code></pre>
  
  <p>Which outputs:</p>
  
  <pre><code>richard@richard-desktop:~/projects/hello-python$ python main.py 
  {
  </code></pre>
  
  <p>If I do print repr(info), I get:</p>
  
  <pre><code>richard@richard-desktop:~/projects/hello-python$ python main.py 
  '{\n    "streams": [\n        {\n            "index": 0,\n            "codec_name": "mpeg2video",\n            "codec_long_name": "MPEG-2 video",\n            "codec_type": "video",\n            "codec_time_base": "1001/48000",\n            "codec_tag_string": "[0][0][0][0]",\n            "codec_tag": "0x0000",\n            "width": 1920,\n            "height": 1080,\n            "has_b_frames": 1,\n            "sample_aspect_ratio": "1:1",\n            "display_aspect_ratio": "16:9",\n            "pix_fmt": "yuv422p",\n            "level": 2,\n            "timecode": "00:59:59:00",\n            "id": "0x1e0",\n            "r_frame_rate": "24000/1001",\n            "avg_frame_rate": "10000/417",\n            "time_base": "1/90000",\n            "start_time": "0.945411"\n        },\n        {\n            "index": 1,\n            "codec_name": "pcm_dvd",\n            "codec_long_name": "PCM signed 20|24-bit big-endian",\n            "codec_type": "audio",\n            "codec_time_base": "1/48000",\n            "codec_tag_string": "[0][0][0][0]",\n            "codec_tag": "0x0000",\n            "sample_fmt": "s32",\n            "sample_rate": "48000",\n            "channels": 2,\n            "bits_per_sample": 0,\n            "id": "0xa0",\n            "r_frame_rate": "0/0",\n            "avg_frame_rate": "0/0",\n            "time_base": "1/90000",\n            "start_time": "0.945411",\n            "duration": "600.595000"\n        }\n    ],\n    "format": {\n        "filename": "/home/richard/projects/hello-python/tests/test_1.mpg",\n        "nb_streams": 2,\n        "format_name": "mpeg",\n        "format_long_name": "MPEG-PS format",\n        "start_time": "0.945411",\n        "duration": "600.595000",\n        "size": "4033241092",\n        "bit_rate": "53723272"\n    }\n}\n'
  </code></pre>
  
  <p>The way I am getting the JSON string is bu running this command:</p>
  
  <pre><code>ffmpeg_command = "ffprobe -v quiet -print_format json -show_format -show_streams %s" % self.absolute_path
  return subprocess.check_output(ffmpeg_command, shell=True)
  </code></pre>