csv2json: Convert CSV to JSON
I needed to convert some comma-separated data into JSON for a JavaScript project I’m working on. Surprisingly I couldn’t find anything online to do it so I knocked up this script. Hope someone finds it useful.
Currently it requires the CSV file to be uploaded online somewhere. If there’s demand I can change it to allow uploading of a file or just pasting in the data.
Comments
September 19th, 2009 at 04:21
Brilliant!
I love it- thanks a million.
October 28th, 2009 at 18:14
Great work!
I was wondering wether you’d let me take a look at the source code, so I can implement it using ActionScript. I have some CSV files I need to convert to JSON. This of course, is part of a bigger project, but unfortunately time is something I lack right now. I’d appreciate it if you could lend me a hand.
Anyway, I know this is a long shot. I understand if you prefer to do otherwise.
Thanks!
October 28th, 2009 at 18:26
Sure thing. Here’s the important bit:
October 28th, 2009 at 18:32
A million thanks!
Really!
November 12th, 2009 at 01:29
Hello,
I tried this but it didn’t work. I put the csv file in google docs and published it and i put in the url to convert but did not work. Any idea why?
Thnks
November 17th, 2009 at 11:45
@zeynel It has to be a plain text CSV file. It won’t work in Google Docs because that creates an HTML file.
December 5th, 2009 at 14:36
Good job Tamlyn!
I needed to convert csv files from command-line.
Here is a small ruby project nicely packaged as a ruby gem:
http://github.com/darwin/csv2json
February 4th, 2010 at 23:23
I would like to convert a .json fle to a .csv file, and in googling for something I found your http://tamlyn.org/2009/06/csv2json-convert-csv-to-json/ about converting .csv to .json.
Do you have a way of converting a .json fle to a .csv file? Certainly would ‘preciate it!
David – New Jersey, U.S.A.
May 18th, 2010 at 15:19
@David I’m afraid converting JSON to CSV is not really possible because JSON is a much more expressive data format than CSV. This means only a very small proportion of JSON files could meaningfully be translated into CSV.
October 3rd, 2010 at 12:09
Thanks a ton! I have used this a lot!
June 27th, 2011 at 22:36
Thanks a lot! Came in handy today.
October 28th, 2011 at 20:10
Thanks for the code. I’ve been looking all over the place for something like this in PHP.
Add a Comment