title: Unexpected end of JSON input while parsing from local storage through JavaScript
body: <p>Here I am trying to write a function which retrieves my data from local storage but it's coming with an error of <i><code>UNEXPECTED END OF JSON INPUT</code></i>.</p>
  
  <pre><code>function saveBookmark(e) {
    e.preventDefault();
  
    //Get form values
    var siteName = document.getElementById('siteName').value;
    var siteUrl = document.getElementById('siteUrl').value;
    var bookmark = {
      name: siteName,
      url: siteUrl
    }
  
    if (localStorage.getItem('bookmarks') == null) {
      var bookmarks = [];
      //add to array
      bookmarks.push(bookmark);
      //set to local storage
      localStorage.setItem('bookmarks', JSON.stringify(bookmarks));
    } else {
      //fetch bookmarks from local strorage
      // HERE IS THE PROBLEM
      var bookmarks = JSON.parse(localStorage.getItem('bookmarks')); 
  
      //add bookmark to array
      bookmarks.push(bookmark);
      //reset back to local storage
      localStorage.setItem('bookmarks', JSON.stringify(bookmarks));
    }
  
  }
  </code></pre>
  
  <p>I can't parse my array back to json ,i.e</p>
  
  <pre><code> var bookmarks = JSON.parse(localStorage.getItem('bookmarks'));
  </code></pre>
  
  <p>what could be the possible solution ?</p>