├── .bowerrc ├── .editorconfig ├── .gitignore ├── .jshintrc ├── .travis.yml ├── Gruntfile.js ├── LICENSE.txt ├── README.md ├── bower.json ├── package.json └── src ├── index.html └── js └── csv-to-json.js /.bowerrc: -------------------------------------------------------------------------------- 1 | { 2 | "directory": "bower_components" 3 | } 4 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # This file is for unifying the coding style for different editors and IDEs 2 | # editorconfig.org 3 | 4 | root = true 5 | 6 | 7 | [*] 8 | end_of_line = lf 9 | charset = utf-8 10 | trim_trailing_whitespace = true 11 | insert_final_newline = true 12 | 13 | [**.{html,css,js,json,jshintrc,bowerrc,yml}] 14 | indent_style = space 15 | indent_size = 4 16 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | dist 2 | build 3 | .project 4 | .settings 5 | *~ 6 | *.diff 7 | *.patch 8 | /*.html 9 | .DS_Store 10 | node_modules 11 | bower_components 12 | -------------------------------------------------------------------------------- /.jshintrc: -------------------------------------------------------------------------------- 1 | { 2 | "camelcase": true, 3 | "immed": true, 4 | "latedef": true, 5 | "newcap": true, 6 | "quotmark": "single", 7 | "trailing": true, 8 | 9 | "node": true, 10 | "devel": false 11 | } 12 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - "0.8" 4 | - "0.10" 5 | before_script: 6 | - npm install -g grunt-cli bower 7 | -------------------------------------------------------------------------------- /Gruntfile.js: -------------------------------------------------------------------------------- 1 | module.exports = function (grunt) { 2 | 'use strict'; 3 | 4 | // Project configuration. 5 | grunt.initConfig({ 6 | pkg: grunt.file.readJSON('package.json'), 7 | 8 | bower: { 9 | install: { 10 | options: { 11 | copy: false // leave components in bower_components/ 12 | } 13 | } 14 | }, 15 | 16 | shell: { 17 | 'bower_csv-js': { 18 | command: [ 19 | 'npm install', 20 | 'grunt' 21 | ].join('&&'), 22 | options: { 23 | execOptions: { 24 | cwd: 'bower_components/csv-js' 25 | } 26 | } 27 | } 28 | }, 29 | 30 | jshint: { 31 | options: { 32 | jshintrc: '.jshintrc' 33 | }, 34 | all: ['Gruntfile.js', 'src/js/**/*.js'] 35 | }, 36 | 37 | copy: { 38 | build: { 39 | files: [ 40 | {expand: true, cwd: 'src/', src: ['**'], dest: 'build/'} 41 | ] 42 | }, 43 | 44 | bower: { 45 | files: [ 46 | { 47 | expand: true, 48 | cwd: 'bower_components/csv-js/dist/', 49 | src: ['**'], 50 | dest: 'build/lib/csv-js/' 51 | }, 52 | { 53 | expand: true, 54 | cwd: 'bower_components/json2/', 55 | src: ['json2.js'], 56 | dest: 'build/lib/json2/' 57 | } 58 | ] 59 | }, 60 | 61 | dist: { 62 | files: [ 63 | {expand: true, cwd: 'build/', src: ['**'], dest: 'dist/'} 64 | ] 65 | } 66 | }, 67 | 68 | clean: { 69 | build: ['build', 'bower_components'], 70 | dist: ['dist'] 71 | } 72 | }); 73 | 74 | // Load Grunt tasks from NPM packages 75 | grunt.loadNpmTasks('grunt-bower-task'); 76 | grunt.loadNpmTasks('grunt-shell'); 77 | grunt.loadNpmTasks('grunt-contrib-jshint'); 78 | grunt.loadNpmTasks('grunt-contrib-copy'); 79 | grunt.loadNpmTasks('grunt-contrib-clean'); 80 | 81 | // Default task(s). 82 | grunt.registerTask('default', [ 83 | 'clean:build', // start with a clean slate 84 | 'clean:dist', 85 | 86 | 'jshint', // lint our JS in src/ 87 | 'copy:build', // copy our JS from src/ to build/ 88 | 89 | 'bower', // install Bower components 90 | 'shell:bower_csv-js', // run post-install commands 91 | 'copy:bower', // copy Bower components to build/lib/ 92 | 93 | 'copy:dist', // copy everything to dist/ 94 | 95 | 'clean:build' // cleanup build/ 96 | ]); 97 | }; 98 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 |  GNU LESSER GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | 9 | This version of the GNU Lesser General Public License incorporates 10 | the terms and conditions of version 3 of the GNU General Public 11 | License, supplemented by the additional permissions listed below. 12 | 13 | 0. Additional Definitions. 14 | 15 | As used herein, "this License" refers to version 3 of the GNU Lesser 16 | General Public License, and the "GNU GPL" refers to version 3 of the GNU 17 | General Public License. 18 | 19 | "The Library" refers to a covered work governed by this License, 20 | other than an Application or a Combined Work as defined below. 21 | 22 | An "Application" is any work that makes use of an interface provided 23 | by the Library, but which is not otherwise based on the Library. 24 | Defining a subclass of a class defined by the Library is deemed a mode 25 | of using an interface provided by the Library. 26 | 27 | A "Combined Work" is a work produced by combining or linking an 28 | Application with the Library. The particular version of the Library 29 | with which the Combined Work was made is also called the "Linked 30 | Version". 31 | 32 | The "Minimal Corresponding Source" for a Combined Work means the 33 | Corresponding Source for the Combined Work, excluding any source code 34 | for portions of the Combined Work that, considered in isolation, are 35 | based on the Application, and not on the Linked Version. 36 | 37 | The "Corresponding Application Code" for a Combined Work means the 38 | object code and/or source code for the Application, including any data 39 | and utility programs needed for reproducing the Combined Work from the 40 | Application, but excluding the System Libraries of the Combined Work. 41 | 42 | 1. Exception to Section 3 of the GNU GPL. 43 | 44 | You may convey a covered work under sections 3 and 4 of this License 45 | without being bound by section 3 of the GNU GPL. 46 | 47 | 2. Conveying Modified Versions. 48 | 49 | If you modify a copy of the Library, and, in your modifications, a 50 | facility refers to a function or data to be supplied by an Application 51 | that uses the facility (other than as an argument passed when the 52 | facility is invoked), then you may convey a copy of the modified 53 | version: 54 | 55 | a) under this License, provided that you make a good faith effort to 56 | ensure that, in the event an Application does not supply the 57 | function or data, the facility still operates, and performs 58 | whatever part of its purpose remains meaningful, or 59 | 60 | b) under the GNU GPL, with none of the additional permissions of 61 | this License applicable to that copy. 62 | 63 | 3. Object Code Incorporating Material from Library Header Files. 64 | 65 | The object code form of an Application may incorporate material from 66 | a header file that is part of the Library. You may convey such object 67 | code under terms of your choice, provided that, if the incorporated 68 | material is not limited to numerical parameters, data structure 69 | layouts and accessors, or small macros, inline functions and templates 70 | (ten or fewer lines in length), you do both of the following: 71 | 72 | a) Give prominent notice with each copy of the object code that the 73 | Library is used in it and that the Library and its use are 74 | covered by this License. 75 | 76 | b) Accompany the object code with a copy of the GNU GPL and this license 77 | document. 78 | 79 | 4. Combined Works. 80 | 81 | You may convey a Combined Work under terms of your choice that, 82 | taken together, effectively do not restrict modification of the 83 | portions of the Library contained in the Combined Work and reverse 84 | engineering for debugging such modifications, if you also do each of 85 | the following: 86 | 87 | a) Give prominent notice with each copy of the Combined Work that 88 | the Library is used in it and that the Library and its use are 89 | covered by this License. 90 | 91 | b) Accompany the Combined Work with a copy of the GNU GPL and this license 92 | document. 93 | 94 | c) For a Combined Work that displays copyright notices during 95 | execution, include the copyright notice for the Library among 96 | these notices, as well as a reference directing the user to the 97 | copies of the GNU GPL and this license document. 98 | 99 | d) Do one of the following: 100 | 101 | 0) Convey the Minimal Corresponding Source under the terms of this 102 | License, and the Corresponding Application Code in a form 103 | suitable for, and under terms that permit, the user to 104 | recombine or relink the Application with a modified version of 105 | the Linked Version to produce a modified Combined Work, in the 106 | manner specified by section 6 of the GNU GPL for conveying 107 | Corresponding Source. 108 | 109 | 1) Use a suitable shared library mechanism for linking with the 110 | Library. A suitable mechanism is one that (a) uses at run time 111 | a copy of the Library already present on the user's computer 112 | system, and (b) will operate properly with a modified version 113 | of the Library that is interface-compatible with the Linked 114 | Version. 115 | 116 | e) Provide Installation Information, but only if you would otherwise 117 | be required to provide such information under section 6 of the 118 | GNU GPL, and only to the extent that such information is 119 | necessary to install and execute a modified version of the 120 | Combined Work produced by recombining or relinking the 121 | Application with a modified version of the Linked Version. (If 122 | you use option 4d0, the Installation Information must accompany 123 | the Minimal Corresponding Source and Corresponding Application 124 | Code. If you use option 4d1, you must provide the Installation 125 | Information in the manner specified by section 6 of the GNU GPL 126 | for conveying Corresponding Source.) 127 | 128 | 5. Combined Libraries. 129 | 130 | You may place library facilities that are a work based on the 131 | Library side by side in a single library together with other library 132 | facilities that are not Applications and are not covered by this 133 | License, and convey such a combined library under terms of your 134 | choice, if you do both of the following: 135 | 136 | a) Accompany the combined library with a copy of the same work based 137 | on the Library, uncombined with any other library facilities, 138 | conveyed under the terms of this License. 139 | 140 | b) Give prominent notice with the combined library that part of it 141 | is a work based on the Library, and explaining where to find the 142 | accompanying uncombined form of the same work. 143 | 144 | 6. Revised Versions of the GNU Lesser General Public License. 145 | 146 | The Free Software Foundation may publish revised and/or new versions 147 | of the GNU Lesser General Public License from time to time. Such new 148 | versions will be similar in spirit to the present version, but may 149 | differ in detail to address new problems or concerns. 150 | 151 | Each version is given a distinguishing version number. If the 152 | Library as you received it specifies that a certain numbered version 153 | of the GNU Lesser General Public License "or any later version" 154 | applies to it, you have the option of following the terms and 155 | conditions either of that published version or of any later version 156 | published by the Free Software Foundation. If the Library as you 157 | received it does not specify a version number of the GNU Lesser 158 | General Public License, you may choose any version of the GNU Lesser 159 | General Public License ever published by the Free Software Foundation. 160 | 161 | If the Library as you received it specifies that a proxy can decide 162 | whether future versions of the GNU Lesser General Public License shall 163 | apply, that proxy's public statement of acceptance of any version is 164 | permanent authorization for you to choose that version for the 165 | Library. 166 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | CSV to JSON 2 | =========== 3 | 4 | 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][wikipedia-data-breach]. Other converters written in server-side languages, which usually submit input and output text using plain HTTP instead of [HTTPS][wikipedia-https], transmitting your data [in the clear as plain, unencrypted text][wikipedia-plaintext], 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][wikipedia-intranet] setting, they should not be used if they are hosted by [untrusted][wikipedia-untrusted] third parties on the unsecured Web. 5 | 6 | Note 7 | ---- 8 | 9 | This converter is a UI -- a shell -- that wraps two external, independent libraries: 10 | 11 | * [Christopher Parker][github-cparker15]'s [CSV JavaScript library][github-csv-js] 12 | * [Douglas Crockford][github-douglascrockford]’s public domain [JSON JavaScript library][github-json-js] 13 | 14 | Please only file bug reports or feature requests pertaining to the converter itself (the user interface) on this repo's issue tracker. 15 | 16 | If you have something to report regarding the functionality of the CSV parser itself, please use the [CSV-js repo's issue tracker][github-csv-js-issues]. 17 | 18 | Building 19 | -------- 20 | 21 | Prerequisites: 22 | 23 | * [Node][nodejs] + [NPM][npmjs] 24 | * [Bower][bower] 25 | * [Grunt CLI][gruntjs] 26 | 27 | After cloning this repo, here's how to build: 28 | 29 | $ npm install 30 | $ grunt 31 | 32 | This will download and build all dependencies, then lint and minify the converter's code and all of its dependencies. 33 | 34 | The final distributable converter resides at `dist/index.html`. 35 | 36 | [wikipedia-data-breach]: http://en.wikipedia.org/wiki/Data_breach 37 | [wikipedia-https]: http://en.wikipedia.org/wiki/HTTP_Secure 38 | [wikipedia-plaintext]: http://en.wikipedia.org/wiki/Plaintext 39 | [wikipedia-intranet]: http://en.wikipedia.org/wiki/Intranet 40 | [wikipedia-untrusted]: http://en.wikipedia.org/wiki/Untrusted 41 | [github-cparker15]: https://github.com/cparker15 42 | [github-csv-js]: https://github.com/cparker15/CSV-js 43 | [github-csv-js-issues]: https://github.com/cparker15/CSV-js/issues 44 | [github-douglascrockford]: https://github.com/douglascrockford 45 | [github-json-js]: https://github.com/douglascrockford/JSON-js 46 | [nodejs]: http://nodejs.org/ 47 | [npmjs]: http://npmjs.org/ 48 | [bower]: http://bower.io/ 49 | [gruntjs]: http://gruntjs.com/ 50 | -------------------------------------------------------------------------------- /bower.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "csv-to-json", 3 | "version": "0.2.2", 4 | "dependencies": { 5 | "csv-js": "git://github.com/cparker15/CSV-js.git", 6 | "json2": "latest" 7 | }, 8 | "ignore": [ 9 | "node_modules", 10 | "components", 11 | "bower_components" 12 | ] 13 | } 14 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "csv-to-json", 3 | "version": "0.2.2", 4 | "description": "A CSV-to-JSON data format converter.", 5 | "homepage": "http://www.cparker15.com/code/utils/csv-to-json/", 6 | "bugs": "https://github.com/cparker15/csv-to-json/issues", 7 | "author": "Christopher Parker (http://www.cparker15.com)", 8 | "contributors": [ 9 | "Christopher Parker (http://www.cparker15.com)", 10 | "Joel Truher (https://github.com/truher)" 11 | ], 12 | "devDependencies": { 13 | "grunt": "~0.4.1", 14 | "grunt-shell": "~0.3.1", 15 | "grunt-bower-task": "~0.2.3", 16 | "grunt-contrib-jshint": "~0.6.0", 17 | "grunt-contrib-copy": "~0.4.1", 18 | "grunt-contrib-clean": "~0.4.1" 19 | }, 20 | "keywords": [ 21 | "csv", 22 | "json", 23 | "converter" 24 | ], 25 | "repository": { 26 | "type": "git", 27 | "url": "git://github.com/cparker15/csv-to-json.git" 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 20 | 21 | 22 | 23 | 24 | 25 | CSV to JSON 26 | 27 | 30 | 31 | 32 | 33 | 34 | 35 | 36 |

Notes:

37 | 38 |
    39 |
  • The CSV text must have a header row.
  • 40 |
  • This utility does not currently check for escaped quotes inside of like quotes (e.g.: "foo, \"bar\" baz").
  • 41 |
42 | 43 |
44 | 45 |

Enter CSV text below.

46 | 47 |
48 |
49 |

50 | 51 |
52 |

53 | 54 | 55 |
56 | 57 | 58 | -------------------------------------------------------------------------------- /src/js/csv-to-json.js: -------------------------------------------------------------------------------- 1 | /** 2 | * csv-to-json: A utility that converts data format from CSV to JSON. 3 | * Copyright (C) 2009-2013 Christopher Parker 4 | * 5 | * csv-to-json is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Lesser General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * csv-to-json is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with csv-to-json. If not, see . 17 | */ 18 | 19 | (function () { 20 | function setMessage (message, error) { 21 | var messageEl = document.getElementById('message'), 22 | errorClass = 'error', 23 | messageContainer = document.createElement('p'); 24 | 25 | while (messageEl.lastChild) { 26 | messageEl.removeChild(messageEl.lastChild); 27 | } 28 | 29 | messageContainer.appendChild(document.createTextNode(message)); 30 | messageEl.appendChild(messageContainer); 31 | 32 | if (error) { 33 | messageEl.className += ' ' + errorClass; 34 | } else { 35 | messageEl.className = messageEl.className.replace(new RegExp(' ' + errorClass, 'g'), ''); 36 | } 37 | } 38 | 39 | window.onload = function () { 40 | document.getElementById('convertForm').onsubmit = function () { 41 | var csvField = this.elements.csv, 42 | jsonField = this.elements.json, 43 | csvText = csvField.value, 44 | csvObjects, jsonText; 45 | 46 | try { 47 | csvObjects = CSV.parse(csvText); 48 | 49 | jsonText = JSON.stringify(csvObjects, null, '\t'); 50 | 51 | jsonField.value = jsonText; 52 | 53 | setMessage('CSV successfully converted to JSON.'); 54 | } catch (e) { 55 | var message = 'Could not convert CSV to JSON: ' + e.message; 56 | 57 | setMessage(message, true); 58 | } 59 | 60 | return false; 61 | }; 62 | }; 63 | }()); 64 | --------------------------------------------------------------------------------