views:

81

answers:

3

Does anyone know how to get a csv url file and convert it to a json object so that I can use google charting tools in js?

A: 

CSV and JSON are different formats. JSON is hierarchical while CSV represents a list of values. So I guess you will need to first parse the CSV (using a parser of course and not implementing yourself). This parser will give you an object which you could then serialize into JSON or probably convert into another object before serializing (once again using a parser) in order to get the desired format.

Darin Dimitrov
A: 

check out this link

Vinay B R
A: 

As far as I know, for most scenarios, you can turn csv into a js Array of Arrays, a Matrix, or any javascript object that follows your charting tool convention.

You may need to:

  1. Get the CSV file content
  2. Parse it
  3. Wrap the results from 2 into your charting tool json(?)
  4. Call your charting library

For 1, if the CSV file is hosted in your domain, you can do a simple XMLHttpRequest, else try searching here "same origin policy".
The tricky part is the point 2. I've seen several failed attempts for parsing CSV files by hand (semicolons can be contained as part of the value, etc)... Check out the link.

Matias