CSV to JSON

Fork me on GitHub
If you'd like to report a bug or request a new feature, please use this project's GitHub issue tracker.

This converter is written entirely in JavaScript and runs completely in the browser. Once the page finishes loading, there are no subsequent calls to the server. Because of this, there's no risk of data breach. Other converters written in server-side languages, which usually submit input and output text using plain HTTP instead of HTTPS, transmitting your data in the clear as plain, unencrypted text, expose you and your data to unnecessary risk. While these server-side converters are good exercises in programming, and may be useful in a trusted intranet setting, they should not be used if they are hosted by untrusted third parties on the unsecured Web.

Conversion of the CSV input text to JavaScript objects is handled by code written by me. Conversion of the JavaScript objects to JSON output text is handled by Douglas Crockford's public domain JSON JavaScript library.

Coming Soon!™

67 Responses to CSV to JSON

  1. Marc Fearby 2011/09/12 at 00:56 #

    This is awesome! Thank you. I was about to copy and paste some records from a table and format as JSON manually so that I could protype web forms in Ext Designer and the thought of having to do it manually was not pleasant. Sure enough, your page was only a quick Google away :-) Excellent work!

  2. Michael Matyus 2011/09/20 at 15:54 #

    Yeah, this rules. Thank you!

  3. Chad S 2011/09/21 at 12:27 #

    Thank you for providing this tool!

  4. Willi 2011/09/22 at 23:18 #

    Very useful. Works also with big datasets. Thank a lot.

  5. David 2011/10/03 at 20:24 #

    Any chance for the code to this be released? Be nice to self host, or port to run via command line rather than web form (e.g. Rhino JS engine or MS JScript for WSH).

    • Christopher Parker 2011/11/16 at 22:04 #

      Thanks for the suggestion, David. You’re not the first person to request something like this. I’m in the process of setting up a GitHub repository for this utility.

      If you have any other suggestions, please feel free to let me know! 

  6. kimberlad 2011/11/01 at 06:28 #

    Code would be good for me to, but totally understand if your looking to corner the market in CSV to JSON conversion :-)

    • Christopher Parker 2011/11/16 at 22:07 #

      Not at all! I’m an avid support of free/libre/open source software. Besides, the converter makes use of the JSON library written by Douglas Crockford; I feel it would only be fair to “pay it forward” and release the code.

      I should have a GitHub repository set up soon.

  7. -s u r k h- 2011/11/02 at 16:05 #

    Thank you so much for this tool. It is extremely helpful and has saved me a LOT of time!

  8. Peter 2011/11/06 at 11:35 #

    Great stuff, very helpful aid to the development process.

  9. Jeff 2012/01/16 at 16:40 #

    You are the man. Thank you.

  10. Barry 2012/01/23 at 13:01 #

    Outstanding!

  11. Jordan 2012/03/13 at 13:02 #

    Thanks for this, saved me in a pinch!

  12. tony 2012/03/15 at 17:14 #

    wow! This is terrific! 

  13. Tacroy 2012/03/30 at 13:59 #

    Just FYI, it looks like there’s a problem with either your example or the converter if you have a quoted segment with a comma and newline in it.
    Eg:
    foo, bar, baz
    12, 34, “5,
    6″
    78, 90, 12
    leaves the json area empty when you hit “convert”.
    (I’ve written a couple of csv parsers in my time so I have an idea of the pitfalls :)

  14. vikas 2012/04/16 at 05:48 #

    Hey it’s awesome stuff, I always prefer this to convert CSV to JSON.. great work..keep it up..

  15. Joaquín 2012/04/20 at 07:58 #

    thank you. It´s useful.

  16. John 2012/05/14 at 15:36 #

    Excellent utility, THANKS!!

  17. Ari Koinuma 2012/05/16 at 12:11 #

    Thank you for creating this tool!  It was a great time saver.

  18. Tim 2012/05/17 at 07:59 #

    Hello Chris,
    Excuse my utter ignorance but what is a ‘Header Row’?
    I’m trying to create a JSON file to import a website blacklist into Untangle web filter.

    I’d appreciate your help.
    regards,
    Tim 

    • Christopher Parker 2012/06/15 at 12:59 #

      In this case, a header row is a row consisting of column labels. Each column label is used as the property name for its corresponding property in each of the JSON objects that gets created from each of the data rows.

      For example, here’s what the CSV might look like to represent some user data:

      userId, username, firstName, lastName
      0, scooper, Sheldon, Cooper
      1, rkoothrappali, Rajesh, Koothrappali
      2, hwolowitz, Howard, Wolowitz
      3, lhofstadter, Leonard, Hofstadter

      The JSON representation of this CSV:

      [
      	{
      		"userId": "0",
      		"username": "scooper",
      		"firstName": "Sheldon",
      		"lastName": "Cooper"
      	},
      	{
      		"userId": "1",
      		"username": "rkoothrappali",
      		"firstName": "Rajesh",
      		"lastName": "Koothrappali"
      	},
      	{
      		"userId": "2",
      		"username": "hwolowitz",
      		"firstName": "Howard",
      		"lastName": "Wolowitz"
      	},
      	{
      		"userId": "3",
      		"username": "lhofstadter",
      		"firstName": "Leonard",
      		"lastName": "Hofstadter"
      	}
      ]

  19. David 2012/05/28 at 18:46 #

    This saved me a LOT of time. Very helpful. THANKS! I’ll be looking forward to the git repo update.

  20. santhosh kumar 2012/06/06 at 02:08 #

    is it possible to get me t javascript code for tis converter ??? it wud be vry helpful !!

  21. Kiernan 2012/07/03 at 01:31 #

    This is great. Thanks. Saves hours.

  22. mangal123 2012/07/06 at 16:36 #

    Thanks. It was a greta a tool.

  23. J2Metal 2012/08/14 at 01:59 #

    This is incredible!!!! Thank you!!!

  24. Doc 2012/09/24 at 04:31 #

    Sorry, doesn’t work properly.

    Converts:

    Fahrzeugname;Modelltyp;Aufbauform;Preis;Platz;Familie;Krafstoffart;Getriebe;PS;
    C 180 CDI BlueEFFICIENCY T-Modell;C-Klasse;T-Modell;34837,25;4;1;Diesel;Manuell;120;
    C 200 CDI BlueEFFICIENCY T-Modell;C-Klasse;T-Modell;36622,25;4;1;Diesel;Manuell;136;

    to:

    [
    {
    "Fahrzeugname;Modelltyp;Aufbauform;Preis;Platz;Familie;Krafstoffart;Getriebe;PS;": "C 180 CDI BlueEFFICIENCY T-Modell;C-Klasse;T-Modell;34837",
    "undefined": "25;4;1;Diesel;Manuell;120;"
    },
    {
    "Fahrzeugname;Modelltyp;Aufbauform;Preis;Platz;Familie;Krafstoffart;Getriebe;PS;": "C 200 CDI BlueEFFICIENCY T-Modell;C-Klasse;T-Modell;36622",
    "undefined": "25;4;1;Diesel;Manuell;136;"
    }
    ]

    • Christopher Parker 2012/09/24 at 20:34 #

      It’s not working because your input doesn’t consist of comma-separated values (CSV). Instead, the values are separated by semicolons.

  25. Ahmed 2012/09/27 at 06:18 #

    Hi Chris,

    How difficult is it to add the ; as a delimiter as well?

    Thanks
    Ahmed

  26. Traconovick 2012/10/21 at 00:55 #

    I do not know what a Header Row is, ad hoc. I pasted comma-delimited E-mail addresses wanting them to be listed in rows and your programs fed back: The CSV text MUST have a header row! I’m confused.

  27. skechy 2012/10/22 at 07:45 #

    Perfect….works perfectly first time…nice utility!

  28. David 2012/10/22 at 08:26 #

    VERY VERY EXTREME COOL !!!
    10x

  29. Karl 2012/11/20 at 02:07 #

    I have a 300mb csv file with 3 million records; will the converter work id I paste that into the window? I know chrome would crash but explorer doesn’t. I have 8 gigs of ram and failing at all attempts at writing something in python to do this for me.

  30. Carlos 2012/11/20 at 08:28 #

    This is really great, great work. Thank you very much. A big hug from Brazil.

  31. Adamo 2012/11/27 at 07:03 #

    When you are next in Rome email me for a free beer or two!

    (can’t fork you on github cos i just don’t get it!)

  32. kd 2012/11/28 at 14:24 #

    beautiful!
    thanks! Kd

  33. David 2012/12/04 at 16:46 #

    Hi Parker, this is great and really works for me! Quite appreciated for providing this conversion tool.

  34. Robin Reid (@brklynchik) 2012/12/07 at 09:17 #

    Hi Chris, someone just turned me onto this, and i am so extremely grateful for your sharing this tool with the world! Now, i am pretty new to programming, and I need to do a visualization with 90,0000 historical records. They are in csv. Please excuse me if this question is totally simplistic to you, but is it enough to copy my file from xcel and paste the data into the box? I have been trying to do a drag and drop and that doesn’t work…however my copy and paste isn’t giving me the correct spelling of my header rows — appreciated.

  35. pedrbedr 2012/12/09 at 07:31 #

    Much obliged.

  36. Brad 2012/12/19 at 13:12 #

    You just saved me so much time I might be able to take a vacation.

  37. Horstwalter 2013/01/08 at 12:26 #

    Thanks, maybe you could make a choice of the selector supporting “,”, “:”, “;”,(usual suspects).

  38. Dilip Shah 2013/01/12 at 17:03 #

    awesome!

  39. Ben Tgb Walters 2013/01/14 at 09:50 #

    This is absolutely perfect! Does what it says on the tin!! Saved me a TON of time!

  40. Srihari 2013/01/23 at 03:39 #

    Thanks! It saved a lot and i didnt look for any other website. Thanks again for keeping it free.

  41. Dan 2013/02/08 at 21:52 #

    Thanks for sharing … excellent tool! and thanks for posting it to github so I can read the code (I’m learning json now) and learn more.

  42. Internet Asshole 2013/02/19 at 16:05 #

    What about the var that holds your Array? This is shit JSON

    • Christopher Parker 2013/03/23 at 22:38 #

      If your goal is to take the output of this converter and embed it in a JavaScript source file, then it’s up to you to take the JSON output and create your own var definition for it.

      Remember, even though JSON looks like JavaScript, it’s not; it’s JSON.

  43. overgroove 2013/02/22 at 16:33 #

    It’s true that the internet will do anything you want it to. Thanks man.

  44. Majid 2013/03/20 at 03:50 #

    Dear Sir,
    What if I wanted to have json in {“source”:1,”target”:0,”value”:1}, format, I have a table and I want to show the network graph in D3.js
    Thanks in advance

    • Christopher Parker 2013/03/23 at 22:32 #

      The idea behind this converter is to convert a CSV-structured table to an array of objects and encode the resulting data structure in JSON.

      So, your CSV looking like this:

      source, target, value
      1, 0, 1
      0, 0, 1
      1, 0, 0
      0, 0, 0
      1, 1, 1
      0, 1, 1
      1, 1, 0
      0, 1, 0

      Would result in JSON that looks like this:

      [
      	{
      		"source": "1",
      		"target": "0",
      		"value": "1"
      	},
      	{
      		"source": "0",
      		"target": "0",
      		"value": "1"
      	},
      	{
      		"source": "1",
      		"target": "0",
      		"value": "0"
      	},
      	{
      		"source": "0",
      		"target": "0",
      		"value": "0"
      	},
      	{
      		"source": "1",
      		"target": "1",
      		"value": "1"
      	},
      	{
      		"source": "0",
      		"target": "1",
      		"value": "1"
      	},
      	{
      		"source": "1",
      		"target": "1",
      		"value": "0"
      	},
      	{
      		"source": "0",
      		"target": "1",
      		"value": "0"
      	}
      ]

      Is that about what you wanted?

  45. Robert Yerex 2013/03/27 at 17:02 #

    Excellent tool!

  46. Anand 2013/04/10 at 01:30 #

    This is just great, saved roller coaster of writing our own parser. Thanks a million

  47. Abe 2013/04/12 at 03:46 #

    This tools saved my bacon on a recent project excellent work.

Trackbacks/Pingbacks

  1. Lessons of the Chewbacca Incident « Binary Bonsai - 2010/09/27

    [...] culled the unneeded data and indexed the visitor values against the busiest day (the 27th). Then I converted the CSV to JSON and wrote a whole heap of garbage code to squeeze it into something I could use. Should you want, [...]

  2. Name_map for reports - Untangle Forums - 2011/02/07

    [...] the header… Then you can write your own file in JSON to import in Untangle or go to this site http://www.cparker15.com/utilities/csv-to-json/ and run the conversion … Save the file in .json format and IMPORT it from the Reports Module… [...]

  3. Converting CSV to JSON | Eli's - 2011/10/06

    [...] Christo­pher Parker’s CSV to JSON Tools ← How Bitcoin could be the base for the Human Credit /* */ [...]

  4. - 2012/08/20

    [...] 2. Convert csv to json using: http://www.cparker15.com/code/utilities/csv-to-json/ [...]

  5. import email safelist from CSV to JSON - 2013/02/19

    [...] 2 *@catlike.es 3 *@ccidsl.com 4 *@centennialoptical.com Then I found some converters out there, http://www.cparker15.com/code/utilities/csv-to-json/ . This will spit out a file in this format: [ { "id": "1", [...]

  6. Bouv's Bookmark Toolbox | Current360 - 2013/04/02

    [...] http://www.cparker15.com/code/utilities/csv-to-json/ [...]