CSV to JSON

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!™

  • RFC 4180 compliance
  • AMD support
  • Grunt
  • JSHint
  • EditorConfig
  • Travis CI
  • Bower
  • External file parser (Browser: Ajax, WebSocket; Node.js: fs, request, etc.)
  • And more! (Request a Feature)
Open in New Window | View Source

62 comments on “CSV to JSON
  1. Marc Fearby says:

    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 says:

    Yeah, this rules. Thank you!

  3. Chad S says:

    Thank you for providing this tool!

  4. Willi says:

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

  5. David says:

    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).

    • 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 says:

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

    • 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- says:

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

  8. Peter says:

    Great stuff, very helpful aid to the development process.

  9. Jeff says:

    You are the man. Thank you.

  10. Barry says:

    Outstanding!

  11. Jordan says:

    Thanks for this, saved me in a pinch!

  12. tony says:

    wow! This is terrific! 

  13. Tacroy says:

    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 says:

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

  15. Joaquín says:

    thank you. It´s useful.

  16. John says:

    Excellent utility, THANKS!!

  17. Ari Koinuma says:

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

  18. Tim says:

    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 

    • 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 says:

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

  20. santhosh kumar says:

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

  21. Kiernan says:

    This is great. Thanks. Saves hours.

  22. mangal123 says:

    Thanks. It was a greta a tool.

  23. J2Metal says:

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

  24. Doc says:

    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;"
    }
    ]

  25. Ahmed says:

    Hi Chris,

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

    Thanks
    Ahmed

    • Not difficult, but then it wouldn’t be a CSV converter.

      I’d be willing to add support for other delimiters if other people find it to be important. Feel free to submit a feature request here: http://github.com/cparker15/csv-to-json/issue

  26. Traconovick says:

    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.

    • So, you pasted something like this…

      user1@example.com,user2@example.com,user3@example.com

      What would you ideally see as JSON output?

    • Traconovick says:

      Thanks fir getting back.
      Yes. I want to enter user1@example.com,user2@example.com,user3@example.com, etc. and have a result of:
      user1@example.com
      user2@example.com
      user3@example.com

  27. skechy says:

    Perfect….works perfectly first time…nice utility!

  28. David says:

    VERY VERY EXTREME COOL !!!
    10x

  29. Karl says:

    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.

    • Honestly, I wouldn’t expect this to work as-is. The converter would likely have to be modified to run the conversion from CSV in batches.

      Please feel free to add a new feature request here to get this on my backlog: http://github.com/cparker15/csv-to-json/issue

  30. Carlos says:

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

  31. Adamo says:

    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 says:

    beautiful!
    thanks! Kd

  33. David says:

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

  34. Robin Reid (@brklynchik) says:

    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.

    • Robin Reid (@brklynchik) says:

      BTW that 90,000 :) not 900,000

    • I would try a copy/paste from Notepad, Notepad++, or some other plain text editor. I’ve not tried copying and pasting directly from Excel.

      I never thought of enabling drag/drop of a CSV file. I like the idea. If you think this would be helpful, please feel free to submit a feature request: http://github.com/cparker15/csv-to-json/issues

  35. pedrbedr says:

    Much obliged.

  36. Brad says:

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

  37. Horstwalter says:

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

  38. Dilip Shah says:

    awesome!

  39. Ben Tgb Walters says:

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

  40. Srihari says:

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

  41. Dan says:

    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 says:

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

    • 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 says:

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

  44. Majid says:

    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

    • 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 says:

    Excellent tool!

  46. Anand says:

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

  47. Abe says:

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

  48. Chris Marsh says:

    Thanks very much! Saved me loads of time and works like a charm.

6 Pings/Trackbacks for "CSV to JSON"
  1. Lessons of the Chewbacca Incident « Binary Bonsai says:

    [...] 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 says:

    [...] the header… Then you can write your own file in JSON to import in Untangle or go to this site /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 says:

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

  4. A little Json processing library « odds'n'sods says:

    [...] 2. Convert csv to json using: /code/utilities/csv-to-json/ [...]

  5. import email safelist from CSV to JSON says:

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

  6. Bouv's Bookmark Toolbox | Current360 says:

    [...] /code/utilities/csv-to-json/ [...]

Follow Me

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Join 5 other subscribers

Recent Tweets
  • RT @FreeConfCall: @bpmilne Hi, you can press #00# to change the hold music, #01# to turn it off and #02# back to default, more info :http:/… 4 days ago
  • A new favorite: Amon Amarth "Deceiver of the Gods" by Metal Blade Records soundcloud.com/metalbladereco… on #SoundCloud 4 days ago
  • RT @mbtaGM: ATTENTION: The #MBTA is SUSPENDED on ALL modes until FURTHER NOTICE. 1 week ago
  • I just liked "HelloSign for Gmail" on Vimeo: vimeo.com/57488523 1 week ago
  • Rappers Delight Rapping Paper fancy.to/0mq18v via @thefancy 2 weeks ago
Follow @cparker15