All the tutorials for the HTML5 file API talk about getting the FileList from a text box. I already have the name of the file (e.g. foo.json), I can’t figure out how to read a file given a file name.
This is not for a web app. I’m producing some data in JSON format, and I’d like to format it using Javascript, essentially producing some interactive bar charts. Much in the way that XML can be formatted with XSLT, I want to distribute a JSON file along with some JavaScript code, and when someone clicks the JavaScript file, they have a simple interactive exploration of the data.
So my first problem is to read the JSON file from Javascript. Note that there’s no webserver involved.
The short answer is “You can’t”. It’s a security issue; if you find a way please submit a bug report to the browser bug-tracker. Its not even possible to pre-fill the dialog with a filename.
However, for your specific usecase; there doesn’t seem to be a need to read a separate file at all. Just include the data as a literal in your JavaScript code.