title: exctract specific value from JSON file
body: <p>I have the following problem. I want to extract the fields of &quot;tracks&quot; separately in this JSON file and make a dataframe. For example I want to make a column with the field pos, a field with the column artist_name, another column with track_uri etc but I get the following error for the field 'pos':</p>
  <pre><code>KeyError                                  Traceback (most recent call last)
  ~\AppData\Local\Temp/ipykernel_15720/1561775056.py in &lt;module&gt;
       18 df3 = pd.json_normalize(js['playlists'])
       19 pd.options.display.float_format ='{:,.1f}'.format
  ---&gt; 20 print(df5['tracks']['pos'])
  
  ~\anaconda3\lib\site-packages\pandas\core\series.py in __getitem__(self, key)
      851 
      852         elif key_is_scalar:
  --&gt; 853             return self._get_value(key)
      854 
      855         if is_hashable(key):
  
  ~\anaconda3\lib\site-packages\pandas\core\series.py in _get_value(self, label, takeable)
      959 
      960         # Similar to Index.get_value, but we do not fall back to positional
  --&gt; 961         loc = self.index.get_loc(label)
      962         return self.index._get_values_for_loc(self, loc, label)
      963 
  
  ~\anaconda3\lib\site-packages\pandas\core\indexes\range.py in get_loc(self, key, method, tolerance)
      352                 except ValueError as err:
      353                     raise KeyError(key) from err
  --&gt; 354             raise KeyError(key)
      355         return super().get_loc(key, method=method, tolerance=tolerance)
      356 
  
  KeyError: 'pos'
  </code></pre>
  <p>Here is the code:</p>
  <pre><code>import json
  import pandas as pd
  import os
  
  path = 'C:\\Users\\sotir\\Desktop\\machinedataset'
  
  filenames = os.listdir(path)
  for filename in sorted(filenames):
      if filename.startswith(&quot;mpd.slice.&quot;) and filename.endswith(&quot;.json&quot;):
          fullpath = os.sep.join((path, filename))
          f = open(fullpath)
          js = json.load(f)
          f.close()
  df1= pd.json_normalize(js['info'])
  df2 = pd.json_normalize(js['playlists'])
  pd.options.display.float_format ='{:,.1f}'.format
  df= df1.merge(df2, how='cross')
  df3 = pd.json_normalize(js['playlists'])
  pd.options.display.float_format ='{:,.1f}'.format
  print(df3['tracks']['pos'])
  </code></pre>
  <p>[json file<a href="https://i.stack.imgur.com/oLiM7.png" rel="nofollow noreferrer">1</a>]</p>
  <p><a href="https://i.stack.imgur.com/AnGlW.png" rel="nofollow noreferrer">screenshot when I run df3.head()</a></p>
  <p>Below is some of the data in the json file</p>
  <pre><code>{
      &quot;info&quot;: {
          &quot;generated_on&quot;: &quot;2017-12-03 08:41:42.057563&quot;, 
          &quot;slice&quot;: &quot;0-999&quot;, 
          &quot;version&quot;: &quot;v1&quot;
      }, 
      &quot;playlists&quot;: [
          {
              &quot;name&quot;: &quot;Throwbacks&quot;, 
              &quot;collaborative&quot;: &quot;false&quot;, 
              &quot;pid&quot;: 0, 
              &quot;modified_at&quot;: 1493424000, 
              &quot;num_tracks&quot;: 52, 
              &quot;num_albums&quot;: 47, 
              &quot;num_followers&quot;: 1, 
              &quot;tracks&quot;: [
                  {
                      &quot;pos&quot;: 0, 
                      &quot;artist_name&quot;: &quot;Missy Elliott&quot;, 
                      &quot;track_uri&quot;: &quot;spotify:track:0UaMYEvWZi0ZqiDOoHU3YI&quot;, 
                      &quot;artist_uri&quot;: &quot;spotify:artist:2wIVse2owClT7go1WT98tk&quot;, 
                      &quot;track_name&quot;: &quot;Lose Control (feat. Ciara &amp; Fat Man Scoop)&quot;, 
                      &quot;album_uri&quot;: &quot;spotify:album:6vV5UrXcfyQD1wu4Qo2I9K&quot;, 
                      &quot;duration_ms&quot;: 226863, 
                      &quot;album_name&quot;: &quot;The Cookbook&quot;
                  }, 
                  {
                      &quot;pos&quot;: 1, 
                      &quot;artist_name&quot;: &quot;Britney Spears&quot;, 
                      &quot;track_uri&quot;: &quot;spotify:track:6I9VzXrHxO9rA9A5euc8Ak&quot;, 
                      &quot;artist_uri&quot;: &quot;spotify:artist:26dSoYclwsYLMAKD3tpOr4&quot;, 
                      &quot;track_name&quot;: &quot;Toxic&quot;, 
                      &quot;album_uri&quot;: &quot;spotify:album:0z7pVBGOD7HCIB7S8eLkLI&quot;, 
                      &quot;duration_ms&quot;: 198800, 
                      &quot;album_name&quot;: &quot;In The Zone&quot;
                  }, 
                  {
                      &quot;pos&quot;: 2, 
                      &quot;artist_name&quot;: &quot;Beyonc\u00e9&quot;, 
                      &quot;track_uri&quot;: &quot;spotify:track:0WqIKmW4BTrj3eJFmnCKMv&quot;, 
                      &quot;artist_uri&quot;: &quot;spotify:artist:6vWDO969PvNqNYHIOW5v0m&quot;, 
                      &quot;track_name&quot;: &quot;Crazy In Love&quot;, 
                      &quot;album_uri&quot;: &quot;spotify:album:25hVFAxTlDvXbx2X2QkUkE&quot;, 
                      &quot;duration_ms&quot;: 235933, 
                      &quot;album_name&quot;: &quot;Dangerously In Love (Alben f\u00fcr die Ewigkeit)&quot;
  </code></pre>