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

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

  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.

  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.

  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. 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 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. This is absolutely perfect! Does what it says on the tin!! Saved me a TON of time!

  39. Srihari says:

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

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

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

  42. overgroove says:

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

  43. 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?

  44. Robert Yerex says:

    Excellent tool!

  45. Anand says:

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

  46. Abe says:

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

  47. Chris Marsh says:

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

  48. steve goswell says:

    is it possible to use a column as a key so that a change in value in that column forces a new array of values?

    eg.

    first-name,last-name,Company,City,State
    Bill,Smith,ABC,Greenwich,CT
    John,Charles,ESPN,New York,NY
    Katie,Jones,ESPN,New York,NY
    Tom,Gross,NBC,Boston,MA

    keyed on Company converts to:

    {
    “ABC” : [
    {
    "first-name": "Bill",
    "last-name": "Smith",
    "City": "Greenwich",
    "State": "CT"
    }
    ],
    “ESPN” : [
    {
    "first-name": "John",
    "last-name": "Charles",
    "City": "New York",
    "State": "NY"
    },
    {
    "first-name": "Katie",
    "last-name": "Jones",
    "City": "New York",
    "State": "NY"
    }
    ],
    “NBC” : [
    {
    "first-name": "Tom",
    "last-name": "Gross",
    "City": "Boston",
    "State": "MA"
    }
    ]
    }

    • Not currently supported, but would be straightforward to implement. Please feel free to open a new feature request via GitHub. I’m actually going to have some time soon to revisit this.

  49. ncschoon says:

    I used a small sample file to create a JSON file with which to test a CouchDB install. When I try to save the document though I get an error bad_Request, document must be a json object. Can anyone tell me why this is happening?

    [
    {
    "STORE": "1",
    "LONGITUDE": "-80.7806678",
    "LATITUDE": "35.3710995"
    },
    {
    "STORE": "2",
    "LONGITUDE": "-80.77777656",
    "LATITUDE": "35.32015444"
    },
    {
    "STORE": "3",
    "LONGITUDE": "-80.76300224",
    "LATITUDE": "35.3389554"
    },
    {
    "STORE": "4",
    "LONGITUDE": "-80.73599692",
    "LATITUDE": "35.29502129"
    },
    {
    "STORE": "5",
    "LONGITUDE": "-80.78213442",
    "LATITUDE": "35.380121"
    }
    ]

6 Pings/Trackbacks for "CSV to JSON"
  1. [...] 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. [...] 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. [...] Christo­pher Parker’s CSV to JSON Tools ← How Bitcoin could be the base for the Human Credit /* */ [...]

  4. [...] 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", [...]

Follow Me

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

Join 5 other subscribers

Calendar
May 2013
S M T W T F S
« Nov    
 1234
567891011
12131415161718
19202122232425
262728293031  
Archives
Categories
%d bloggers like this: