Parse a Directory of json files with python
<p>I have been looking for how to do this but I cannot. 
I have a directory of .json files and I am supposed to parse each one.
I know I have to use glob and os.
I feel like the logic behind it is loop over the directory and when reading each file extract the data that is needed, but I cannot find anywhere to help me nor do I know the syntax. 
If its against stack rules and people think this is me asking for answers to homework that is fine I can just search elsewhere, this isn't homework I just don't understand.  </p>

<p>Assuming that your JSON files are named with a <code>.json</code> extension and that they are in the same directory that you are running the script from:</p>

<pre><code>import json
from glob import glob

data = []
for file_name in glob('*.json'):
    with open(file_name) as f:
        data.append(json.load(f))
</code></pre>

<p>This will give you a list of parsed JSON objects (dictionaries and/or lists).</p>

<p>If you need to access the files in another directory you can construct your glob pattern like this:</p>

<pre><code>import os.path

pattern = os.path.join('/path/to/json/files', '*.json')
for file_name in glob(pattern):
    ....
</code></pre>

python json parsing