Hello!
I would like to import a json file and save it into a var.
I've attached an example.json file. I would like to have an object literal after importing the json:
var myvar = {
"Document_type" : "FMEA",
"sheet_name" : "Example",
"header_row" : 14
};I've played around with java.io library to read the file line by line, but I'm wondering if there is a simpler solution (a dedicated json library perhaps?).
Here is my code so far:
load(".lib/ui.js");
function readFileLineByLine() {
// open pop-up window to select json file
var file = openFile(["*.json"]);
if(file){
var reader = new java.io.BufferedReader( new java.io.FileReader(file) );
var mystring= "";
while (reader.ready()){
line = reader.readLine();
// console.log(line); // this won't work. It complains about unmatched brachets
mystring = mystring.concat(line);
}
reader.close();
// console.log(mystring); // this does not work either, similar issue.
} else {
alert("No input file selected");
}
}
which is NOT working as I can't store the content of my string into a var, neither using console.log() for that matter. Any ideas on what am I doing wrong?