[Tutor] Parsing JSON with Python

Alan Gauld alan.gauld at btinternet.com
Fri Dec 12 00:56:10 CET 2014

On 11/12/14 23:22, Martin A. Brown wrote:

>    arr = json.loads('{ "name": "Joe", "address": "111 Street" }')
>    arr.get('address')
> Here are some notes about why:
>    # -- You will notice I used a variable called 'arr' instead of
>    #    array, because there is a module called array, and I may
>    #    (one day) want to use it.
>    >>> arr
>    {'name': 'Joe', 'address': '111 Street'}

But even arr is a bad name choice because it implies an array
structure is being stored, which it isn't, it's a dictionary
(which in the general case can be called an "associative array"
but in Python-land that's extremely rare). arrays are a very
specific type of data and using a variable name that sounds
like array is liable to lead to false assumptions further down
the line.

Since this data stores a name and address use a name that reflects that, 
such as location, home, or even just address... Names should nearly 
always reflect their logical purpose not their data type.

Alan G
Author of the Learn to Program web site
Follow my photo-blog on Flickr at:

More information about the Tutor mailing list