JSFiddle - React, Tailwind, and code Playground

by shanieMoonlight

HTML

<input type='file' accept='text/plain' onchange='openFile(event)'>

JavaScript

var openFile = function(event) {

  var input = event.target
  var reader = new FileReader()

  reader.onload = function(e) {

    const jsonTxt = e.target.result.toString()
    const jsonTxtArray = '[' + jsonTxt + ']'
    console.log('obj', JSON.parse(jsonTxtArray))

  }

  reader.readAsText(input.files[0]);

}