title: How to decode data off spotify api
body: <p>I successfully got the Spotify API to work with spotify-web-api-js, but I have no idea how to decode this. I want to be able display the title and artist of the song currently playing on a HTML page.</p>
  
  <p>Right now to test, I'm trying to use <code>&lt;script&gt;document.getElementById("song").innerHTML = data.timestamp&lt;/script&gt;</code> (<code>data</code> is the stuff from the Spotify api) to get the timestamp since I don't know what the format is to go deeper into the Spotify response. I get an <code>Uncaught TypeError: Cannot read property 'timestamp' of undefined</code>. </p>
  
  <p>Note: I'm new to coding</p>
  
  <p>Here's the javascript that gets the stuff from Spotify:</p>
  
  <pre><code>var SpotifyWebApi = require('spotify-web-api-js');
  var spotifyApi = new SpotifyWebApi();
  var data;
  
  spotifyApi.setAccessToken('token')
  spotifyApi.getMyCurrentPlayingTrack('title')
  .then(function(data) {
      console.log('Now playing', data);
    }, function(err) {
      console.error(err);
    });
  </code></pre>
  
  <p>Here's the part of the html webpage that supposed to show the title of the song (in this case the timestamp, for testing purposes):</p>
  
  <pre><code>  &lt;body&gt;
        &lt;div class=center&gt;
          &lt;h1 id="song"&gt;&lt;/h1&gt;
          &lt;h2&gt;Luna Li&lt;/h2&gt;
          &lt;script&gt;document.getElementById("song").innerHTML = data.timestamp&lt;/script&gt;
        &lt;/div&gt;
    &lt;/body&gt;
  </code></pre>
  
  <p>Response from spotify:</p>
  
  <pre><code>{
    "timestamp" : 1592617721303,
    "context" : {
      "external_urls" : {
        "spotify" : "https://open.spotify.com/album/3GU8BzFEAdFSRjc8jZkL3S"
      },
      "href" : "https://api.spotify.com/v1/albums/3GU8BzFEAdFSRjc8jZkL3S",
      "type" : "album",
      "uri" : "spotify:album:3GU8BzFEAdFSRjc8jZkL3S"
    },
    "progress_ms" : 27470,
    "item" : {
      "album" : {
        "album_type" : "compilation",
        "artists" : [ {
          "external_urls" : {
            "spotify" : "https://open.spotify.com/artist/0LyfQWJT6nXafLPZqxe9Of"
          },
          "href" : "https://api.spotify.com/v1/artists/0LyfQWJT6nXafLPZqxe9Of",
          "id" : "0LyfQWJT6nXafLPZqxe9Of",
          "name" : "Various Artists",
          "type" : "artist",
          "uri" : "spotify:artist:0LyfQWJT6nXafLPZqxe9Of"
        } ],
        "available_markets" : [ "AD", "AE", "AR", "AT", "AU", "BE", "BG", "BH", "BO", "BR", "CA", "CH", "CL", "CO", "CR", "CY", "CZ", "DE", "DK", "DO", "DZ", "EC", "EE", "EG", "ES", "FI", "FR", "GB", "GR", "GT", "HK", "HN", "HU", "ID", "IE", "IL", "IN", "IS", "IT", "JO", "KW", "LB", "LI", "LT", "LU", "LV", "MA", "MC", "MT", "MX", "MY", "NI", "NL", "NO", "NZ", "OM", "PA", "PE", "PH", "PL", "PS", "PT", "PY", "QA", "RO", "SA", "SE", "SG", "SK", "SV", "TH", "TN", "TR", "TW", "US", "UY", "VN", "ZA" ],
        "external_urls" : {
          "spotify" : "https://open.spotify.com/album/3GU8BzFEAdFSRjc8jZkL3S"
        },
        "href" : "https://api.spotify.com/v1/albums/3GU8BzFEAdFSRjc8jZkL3S",
        "id" : "3GU8BzFEAdFSRjc8jZkL3S",
        "images" : [ {
          "height" : 640,
          "url" : "https://i.scdn.co/image/ab67616d0000b2730bdf4dd39843ad48c5b66bc4",
          "width" : 640
        }, {
          "height" : 300,
          "url" : "https://i.scdn.co/image/ab67616d00001e020bdf4dd39843ad48c5b66bc4",
          "width" : 300
        }, {
          "height" : 64,
          "url" : "https://i.scdn.co/image/ab67616d000048510bdf4dd39843ad48c5b66bc4",
          "width" : 64
        } ],
        "name" : "La La Land (Original Motion Picture Soundtrack)",
        "release_date" : "2016-12-09",
        "release_date_precision" : "day",
        "total_tracks" : 15,
        "type" : "album",
        "uri" : "spotify:album:3GU8BzFEAdFSRjc8jZkL3S"
      },
      "artists" : [ {
        "external_urls" : {
          "spotify" : "https://open.spotify.com/artist/6kXm2YCtdUOpRYNKeKhfue"
        },
        "href" : "https://api.spotify.com/v1/artists/6kXm2YCtdUOpRYNKeKhfue",
        "id" : "6kXm2YCtdUOpRYNKeKhfue",
        "name" : "Ryan Gosling",
        "type" : "artist",
        "uri" : "spotify:artist:6kXm2YCtdUOpRYNKeKhfue"
      }, {
        "external_urls" : {
          "spotify" : "https://open.spotify.com/artist/68Uwx1d3EbjDJhYsLjqvIq"
        },
        "href" : "https://api.spotify.com/v1/artists/68Uwx1d3EbjDJhYsLjqvIq",
        "id" : "68Uwx1d3EbjDJhYsLjqvIq",
        "name" : "Emma Stone",
        "type" : "artist",
        "uri" : "spotify:artist:68Uwx1d3EbjDJhYsLjqvIq"
      } ],
      "available_markets" : [ "AD", "AE", "AR", "AT", "AU", "BE", "BG", "BH", "BO", "BR", "CA", "CH", "CL", "CO", "CR", "CY", "CZ", "DE", "DK", "DO", "DZ", "EC", "EE", "EG", "ES", "FI", "FR", "GB", "GR", "GT", "HK", "HN", "HU", "ID", "IE", "IL", "IN", "IS", "IT", "JO", "KW", "LB", "LI", "LT", "LU", "LV", "MA", "MC", "MT", "MX", "MY", "NI", "NL", "NO", "NZ", "OM", "PA", "PE", "PH", "PL", "PS", "PT", "PY", "QA", "RO", "SA", "SE", "SG", "SK", "SV", "TH", "TN", "TR", "TW", "US", "UY", "VN", "ZA" ],
      "disc_number" : 1,
      "duration_ms" : 236506,
      "explicit" : false,
      "external_ids" : {
        "isrc" : "USUG11600652"
      },
      "external_urls" : {
        "spotify" : "https://open.spotify.com/track/4r9hiElqKWMPT4Z3vN2exq"
      },
      "href" : "https://api.spotify.com/v1/tracks/4r9hiElqKWMPT4Z3vN2exq",
      "id" : "4r9hiElqKWMPT4Z3vN2exq",
      "is_local" : false,
      "name" : "A Lovely Night",
      "popularity" : 62,
      "preview_url" : "https://p.scdn.co/mp3-preview/b315c0bd334edba2f571a4d5e1986ae544d8cf1b?cid=1f307ec00d7b4f3186cb56d56162cab6",
      "track_number" : 4,
      "type" : "track",
      "uri" : "spotify:track:4r9hiElqKWMPT4Z3vN2exq"
    },
    "currently_playing_type" : "track",
    "actions" : {
      "disallows" : {
        "resuming" : true
      }
    },
    "is_playing" : true
  }
  </code></pre>
  
  <p>Is there an easy way to get the title of the song and artist from this? I feel like you could do it with <code>&lt;script&gt;document.getElementById("song").innerHTML = data.timestamp&lt;/script&gt;</code> but I'm not sure how to navigate through the Spotify response.</p>