JSON data parse error

183 views
Skip to first unread message

dunba...@gmail.com

unread,
Feb 15, 2016, 12:07:38 PM2/15/16
to Google Visualization API
Hi, 

I'm using the Query/response method to download data from an API source into a dataTable, but I get "SyntaxError: Unexpected token ':'. Parse error." followed by a timeout alert. However, in the console, the downloaded data (pasted below) appears ok to me. Can anyone spot what the problem is, and how to fix it? 

Thanks, 
Nick 


{
    "realtime_start": "2016-02-15",
    "realtime_end": "2016-02-15",
    "seriess": [{
        "id": "GNPCA",
        "realtime_start": "2016-02-15",
        "realtime_end": "2016-02-15",
        "title": "Real Gross National Product",
        "observation_start": "1929-01-01",
        "observation_end": "2014-01-01",
        "frequency": "Annual",
        "frequency_short": "A",
        "units": "Billions of Chained 2009 Dollars",
        "units_short": "Bil. of Chn. 2009 $",
        "seasonal_adjustment": "Not Seasonally Adjusted",
        "seasonal_adjustment_short": "NSA",
        "last_updated": "2015-07-30 09:03:15-05",
        "popularity": 25,
        "notes": "BEA Account Code: A001RX1"
    }
    ]
}

Nick Dunbar

unread,
Feb 17, 2016, 9:51:20 AM2/17/16
to google-visua...@googlegroups.com
Any thoughts on this one? I appreciate this is XML but I am trying to avoid having to learn Python to do this properly. 

All help appreciated. 
Nick 

--
You received this message because you are subscribed to a topic in the Google Groups "Google Visualization API" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-visualization-api/dmBdIMqe3_U/unsubscribe.
To unsubscribe from this group and all its topics, send an email to google-visualizati...@googlegroups.com.
To post to this group, send email to google-visua...@googlegroups.com.
Visit this group at https://groups.google.com/group/google-visualization-api.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-visualization-api/f503f439-d42d-4f03-883d-34beb59fe529%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Sergey Grabkovsky

unread,
Feb 17, 2016, 9:55:06 AM2/17/16
to google-visua...@googlegroups.com
Hi Nick,

Are you trying to use the google.visualization.Query to load the JSON file? Or are you using XHR or jQuery to load it?

You received this message because you are subscribed to the Google Groups "Google Visualization API" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-visualizati...@googlegroups.com.

To post to this group, send email to google-visua...@googlegroups.com.
Visit this group at https://groups.google.com/group/google-visualization-api.

For more options, visit https://groups.google.com/d/optout.
--

unnamed.gif

Sergey Grabkovsky

Software Engineer

Google, Inc

gra...@google.com


Nick Dunbar

unread,
Feb 17, 2016, 10:18:54 AM2/17/16
to google-visua...@googlegroups.com
Hi Sergey, 

I am using google.visualization.Query with the following code: 

query.send(handleQueryResponse);
function handleQueryResponse(response) {
  if (response.isError()) {
    alert('Error in query: ' + response.getMessage() + ' ' + response.getDetailedMessage());
    return;
}

(note that the API is the Federal Reserve which requires a dedicated API key)

I also have the jQuery API loaded, and I know there is a jQuery.parseJSON method but I don't know how it works. 

Thanks for your assistance,

Nick 

Sergey Grabkovsky

unread,
Feb 17, 2016, 11:09:15 AM2/17/16
to google-visua...@googlegroups.com
Okay, so first of all, the google.visualization.Query expects the response to be jsonp, which means that it's a JSON object passed to a function, i.e. "processResponse({"abc": 123})". Setting the sendMethod option to 'xhr' should make it work (assuming there are no cross-domain issues).

However, there is another problem. google.visualization.Query only works with Google Charts Data Sources, as described here. As you can hopefully see from the "Response Format" documentation, the query expects a number of things to exist in the response JSON, such as a "reqId" and "status". Another thing is that it expects a DataTable to be included in the response (assuming that no error has occurred).

Your DataSource's response obviously does not include any of these things, and will fail again for these reasons after you fix the first issue (with the Query expecting a jsonp response). Your best bet would probably be to use $.ajax to fetch your json, and some custom JavaScript code to coerce it into a DataTable.


For more options, visit https://groups.google.com/d/optout.

Nick Dunbar

unread,
Feb 17, 2016, 12:07:02 PM2/17/16
to google-visua...@googlegroups.com
Hi Sergey, 
Thanks for getting back to me. I definitely need to get a dataTable out of my JSON so it looks like I have some work to do on this front. 
Regards, 
Nick 

Reply all
Reply to author
Forward
0 new messages