I have a simple script that pulls about 30,000 characters of JSON.
I get SyntaxError: Unexpected token: F (line 12)
when I try to parse it with JSON.parse()
or Utilities.jsonParse();
function refresh() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];
sheet.clear();
var text = UrlFetchApp.fetch("http://blablah/json");
Logger.log(text.getContentText());
//error SyntaxError: Unexpected token: F (line 12)
json = JSON.parse(text);
)
The logger only shows about 59 lines of the JSON, but I was told that the logger has a space limit - but I'm not so sure that's it.
Running on my own server, JSON.parse parses the data just fine and so does jQuery get().
So I'm thinking UrlFetchApp.fetch() just can't get long files?
Hard to accept and I've found no documentation about it :(
You can check the UrlFetch and other services limitations on the new Apps Script dashboard. From my experience, Logger.log has a much more tighter limitation for a single log than UrlFetch, it's possible that UrlFetch is getting it fine, Logger.log is not showing it and you're running into other problem.
Try placing the getContentText
result somewhere else, e.g. a spreadsheet cell. Or split it and call logger log in a for-loop.
A possible error that you might be facing (besides the quota limitation) is character encoding, getContentText
has an optional parameter where you might inform the encoding of the page, have you checked that?
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