how can i use a json output in python
Question: I am trying to figure out how to get a `json` output in `python`. here is the
url:

[http://maps.googleapis.com/maps/api/distancematrix/json?origins=Vancouver+BC|Seattle&destinations=San+Francisco|Victoria+BC&mode=bicycling&language=fr-
FR&sensor=false](http://maps.googleapis.com/maps/api/distancematrix/json?origins=Vancouver+BC|Seattle&destinations=San+Francisco|Victoria+BC&mode=bicycling&language=fr-
FR&sensor=false)

whose output would be like this

    
    
    {
      "status": "OK",
      "origin_addresses": [ "Vancouver, BC, Canada", "Seattle, État de Washington, États-Unis" ],
      "destination_addresses": [ "San Francisco, Californie, États-Unis", "Victoria, BC, Canada" ],
      "rows": [ {
        "elements": [ {
          "status": "OK",
          "duration": {
            "value": 340110,
            "text": "3 jours 22 heures"
          },
          "distance": {
            "value": 1734542,
            "text": "1 735 km"
          }
        }, {
          "status": "OK",
          "duration": {
            "value": 24487,
            "text": "6 heures 48 minutes"
          },
          "distance": {
            "value": 129324,
            "text": "129 km"
          }
        } ]
      }, {
        "elements": [ {
          "status": "OK",
          "duration": {
            "value": 288834,
            "text": "3 jours 8 heures"
          },
          "distance": {
            "value": 1489604,
            "text": "1 490 km"
          }
        }, {
          "status": "OK",
          "duration": {
            "value": 14388,
            "text": "4 heures 0 minutes"
          },
          "distance": {
            "value": 135822,
            "text": "136 km"
          }
        } ]
      } ]
    }
    

How can i print this output in python ?  
Can anyone help me out ?  
Thanks


Answer: Depending on your version of Python, importing JSON might not be enough.

If you are running a version of python less than 2.6, you need to install
simplejson from your commandline.

> pip install simplejson

After that, just import normally.

    
    
    import simplejson as json
    

The following should work in Python 2.x. There are a few differences in 3.x,
I'll leave that as an exercise for your imagination.

    
    
    try:
        import json
    except:
        import simplejson as json
    url = "http://maps.googleapis.com/maps/api/distancematrix/json?origins=Vancouver+BC|Seattle&destinations=San+Francisco|Victoria+BC&mode=bicycling&language=fr-FR&sensor=false"
    contents = urllib2.urlopen(url).read()
    json_array = json.loads(contents)
    print repr(json_array)
    

