I am looking to read a json file, namely config.json
from a AppScript to generate a Google Form from the meta data in the config.json
. I am not sure how to read the JSON file - could someone help me with it please? Some example code would be greatly appreciated.. Thanks
Assuming that your file is in Google Drive, you can use the DriveApp service to read the file and parse it.
function getFileContent() {
var fileName = "config.json.txt";
var files = DriveApp.getFilesByName(fileName);
if (files.hasNext()) {
var file = files.next();
var content = file.getBlob().getDataAsString();
var json = JSON.parse(content);
Logger.log(json);
}
}
Make sure that Google Drive has not converted the text file into a native format else the script won't be able to parse it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With