title: Uploading a JSON file and using it
body: <p>How can I upload a JSON file on some click on a button on my web page say "import", and use it to store in a variable to use and update it using JavaScript.</p>
  
  <p>I have gone through the other posts but could not find any answer.</p>
  
  <p>I am saving the JSON variable using this function:</p>
  
  <pre><code>function save(filename, data){
  
      if(!data) {
          alert('error : No data')
          return;
      }
  
      if(typeof data === "object"){
          data = JSON.stringify(data, undefined, 4)
      }
  
      var blob = new Blob([data], {type: 'text/json'}),
          e    = document.createEvent('MouseEvents'),
          a    = document.createElement('a')
  
      a.download = filename
      a.href = window.URL.createObjectURL(blob)
      a.dataset.downloadurl =  ['text/json', a.download, a.href].join(':')
      e.initMouseEvent('click', true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null)
      a.dispatchEvent(e)
   }
  </code></pre>
  
  <p>This is working fine and it downloads the file on clicking another button say "export".
  How upload this file back and make a JSON variable of this file data?</p>