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

Open in New Window | View Source

  • Trackback ( 5 )
  • Comments ( 59 )
    • Marc Fearby
    • September 12th, 2011 12:56am

    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!

    • Michael Matyus
    • September 20th, 2011 3:54pm

    Yeah, this rules. Thank you!

    • Chad S
    • September 21st, 2011 12:27pm

    Thank you for providing this tool!

    • Willi
    • September 22nd, 2011 11:18pm

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

    • David
    • October 3rd, 2011 8:24pm

    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! 

    • kimberlad
    • November 1st, 2011 6:28am

    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.

    • -s u r k h-
    • November 2nd, 2011 4:05pm

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

    • Peter
    • November 6th, 2011 11:35am

    Great stuff, very helpful aid to the development process.

    • Jeff
    • January 16th, 2012 4:40pm

    You are the man. Thank you.

    • Barry
    • January 23rd, 2012 1:01pm

    Outstanding!

    • Jordan
    • March 13th, 2012 1:02pm

    Thanks for this, saved me in a pinch!

    • tony
    • March 15th, 2012 5:14pm

    wow! This is terrific! 

    • Tacroy
    • March 30th, 2012 1:59pm

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

    • vikas
    • April 16th, 2012 5:48am

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

    • Joaquín
    • April 20th, 2012 7:58am

    thank you. It´s useful.

    • John
    • May 14th, 2012 3:36pm

    Excellent utility, THANKS!!

    • Ari Koinuma
    • May 16th, 2012 12:11pm

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

    • Tim
    • May 17th, 2012 7:59am

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

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

    • santhosh kumar
    • June 6th, 2012 2:08am

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

      Sure! Just visit the GitHub project page and you're good to go.

    • Kiernan
    • July 3rd, 2012 1:31am

    This is great. Thanks. Saves hours.

    • mangal123
    • July 6th, 2012 4:36pm

    Thanks. It was a greta a tool.

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

    • Doc
    • September 24th, 2012 4:31am

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

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

    • Ahmed
    • September 27th, 2012 6:18am

    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

    • Traconovick
    • October 21st, 2012 12:55am

    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
      • December 8th, 2012 6:24pm

      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

    • skechy
    • October 22nd, 2012 7:45am

    Perfect....works perfectly first time...nice utility!

    • David
    • October 22nd, 2012 8:26am

    VERY VERY EXTREME COOL !!!
    10x

    • Karl
    • November 20th, 2012 2:07am

    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

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

    • Adamo
    • November 27th, 2012 7:03am

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

    • kd
    • November 28th, 2012 2:24pm

    beautiful!
    thanks! Kd

    • David
    • December 4th, 2012 4:46pm

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

    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)
      • December 7th, 2012 9:17am

      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

    • pedrbedr
    • December 9th, 2012 7:31am

    Much obliged.

    • Brad
    • December 19th, 2012 1:12pm

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

    • Horstwalter
    • January 8th, 2013 12:26pm

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

    • Dilip Shah
    • January 12th, 2013 5:03pm

    awesome!

    • Ben Tgb Walters
    • January 14th, 2013 9:50am

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

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

    • Dan
    • February 8th, 2013 9:52pm

    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.

    • Internet Asshole
    • February 19th, 2013 4:05pm

    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.

    • overgroove
    • February 22nd, 2013 4:33pm

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

    • Majid
    • March 20th, 2013 3:50am

    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?

    • Robert Yerex
    • March 27th, 2013 5:02pm

    Excellent tool!

  1. September 27th, 2010
    Trackback from : Lessons of the Chewbacca Incident « Binary Bonsai
  2. February 7th, 2011
  3. October 6th, 2011
  4. August 20th, 2012
  5. February 19th, 2013