Data Source JSON response implementation

258 views
Skip to first unread message

Claudio

unread,
Feb 4, 2021, 6:59:24 PM2/4/21
to Google Visualization API
Hi, I am testing an endpoint as a data source. Its raw response now is:

google.visualization.Query.setResponse({"status":"ok","table":{"rows":[{"c":[{"v":1.0}]},{"c":[{"v":3.0}]}],"cols":[{"id":"Col1","type":"number"}]},"reqId":"0"})

But when the response is processed after query.send(), I get the error: "Unexpected token ) in JSON at position 121".

But, as far as I can tell, the JSON format is as specified in the documentation (with the detail of quotes around names because I interpret this is proper for "strict" JSON). 

What could be going wrong ?

Thanks in advance!

Claudio

unread,
Feb 4, 2021, 7:05:25 PM2/4/21
to Google Visualization API
PS: reqId is properly taken from the query parameter, I just wrote "0" in the object for an example.

Claudio

unread,
Feb 4, 2021, 9:19:38 PM2/4/21
to Google Visualization API
So.. finally found what was wrong...

The client library error was thrown after two "regexes" that remove the handler function from the response string: 

 c = c.replace(/^[\s\S]*google\.visualization\.Query\.setResponse\(/g, ""),
 c = c.replace(/\);[\s]*$/g, ""),

The last of them, removes ");" from the end of the response string, so it seems a ";" at the end of the string is needed to make it work.

I missed this in the examples , but the first two boxes here omit it. Left feedback.

Thanks for reading :)

Daniel LaLiberte

unread,
Feb 5, 2021, 12:56:06 AM2/5/21
to Google Visualization API
Thanks for your reports here and your feedback.  This may be considered a bug in how the response is processed since it probably should not fail due to missing the semicolon.
Reply all
Reply to author
Forward
0 new messages