How to parse a 'JSON string' file in Python?
Question: I am working on something that is quite similar to [this
topic](http://stackoverflow.com/questions/13938183/python-json-string-to-list-
of-dictionaries-getting-error-when-iterating).I downloaded a file which seems
like to be a JSON file. But when I open it in notepad, I found that it is a
very long list of dictionaries. The file essentially looks like this:

    
    
    [
    {'time':1, 'value':100},
    {'time':2, 'value':105},
    {'time':3, 'value':120}
    ]
    

I tried to load this 'JSON file' into Python like this:

    
    
    import json
    with open('data.json') as data_file:
        data = json.loads(data_file)
    

but got an error:

    
    
    TypeError: expected string or buffer
    

How can I load this file correctly into Python? I would like to iterate thru
each row to extract all the 'values'. Thanks!


Answer: Use `json.load`:

    
    
    with open('data.json') as data_file:
        data = json.load(data_file)
    

The primary difference between `json.load` and `json.loads` is that
`json.load` accepts a file (or file-like object) to read and load JSON from,
whereas `json.loads` loads JSON from a string.

