0

I have this function in google script that fetches a JSON from the web, but it fails when i try to execute it, citing:

SyntaxError: Unexcpected character in string: '\''

Script:

function getTheFeed(url){
    var response = UrlFetchApp.fetch(url);
    var json = response.getContentText();
    var Jdata = JSON.parse(json);
    Jdata = json;
    return Jdata;
}

I've tested the URL, by importing it in a string and doing JSON.parse on it, and i get no errors in Google Chrome.

Any other ideas?

UPDATE: After doing Logger.Log turns out the JSON is being cut after 8KB of response. Nothing conflicting at the place the request ends...

Still looking for a response...

R0b0tn1k
  • 4,256
  • 14
  • 46
  • 64
  • Can you add a `console.log(json);` and share the result to see what do you want to parse? – albciff Jan 15 '15 at 12:45
  • Yeah, i just did, it appears the JSON is incomplete... Why is the JSON incomplete? – R0b0tn1k Jan 15 '15 at 12:53
  • Response ends after 8KB. – R0b0tn1k Jan 15 '15 at 12:57
  • This is probably due the google service quotas limitation in apps script `URL fetch URL length` is 8kb... so probably the error parsing is because the response is incomplete. Check current limitations here: `https://developers.google.com/apps-script/guides/services/quotas` – albciff Jan 15 '15 at 13:17
  • But, that's headers, this is the response body? – R0b0tn1k Jan 15 '15 at 13:20
  • See below, even the error message should be different if that's the case, i get no error message on the URL fetch line... – R0b0tn1k Jan 15 '15 at 13:21

1 Answers1

0

Try to use alert(url) and see what you really get. It could be an escaping issue which sometimes browsers handle properly when you enter it directly in the address bar.

EDIT: Different browsers have different limits. But generally the limit is around 2,000 characters for the GET method of a URL. See: What is the character limit on URL

Community
  • 1
  • 1
Georgi
  • 189
  • 2
  • 12
  • I just over parsed the url, and i got an error on the UrlFetchApp.fetch line. So it's not the URL. – R0b0tn1k Jan 15 '15 at 12:51
  • could you include some more debugging as albciff recommended earlier and post it? – Georgi Jan 15 '15 at 12:52
  • It depends on the browsers, but if you have such a long URL, try to restrict your GET parameters. Maybe you could consider POST request? – Georgi Jan 15 '15 at 13:08