MASSIMO FRANCIOSA

It might happen during the development of your web application to have the need to load and save a file using only client side code.

a typical example might be to load a JSON file, parse it into an object, then save it back.

Load a JSON file in javascript

Loading file from Javascript is relatively easy.
All we need to do is an input field of type file (the ones used for uploading a file) and then use the FileReader object to retrieve the content and parse it into an object.

<input type="file" id="fileText" />

Bear in mind that the readAsText method is asyncronous: this means that we need to set a callback with the code that needs to run after the file has finished to load.