darwin / csv2json Goto Github PK
View Code? Open in Web Editor NEWA gem useful for converting CSV files to JSON from command-line
License: MIT License
A gem useful for converting CSV files to JSON from command-line
License: MIT License
/usr/bin/ruby1.8 -I"lib:lib:test" "/usr/lib/ruby/gems/1.8/gems/rake-0.8.6/lib/rake/rake_test_loader.rb" "test/test_csv2json.rb"
(in /home/hoffmanc/ocer/darwin-csv2json-0436af7)
All dependencies seem to be installed.
Loaded suite /usr/lib/ruby/gems/1.8/gems/rake-0.8.6/lib/rake/rake_test_loader
Started
population_comma.csv
F
Finished in 0.024187 seconds.
__bind_1269015901_504391' ./test/test_csv2json.rb:12:in
open'__bind_1269015901_504391' ./test/test_csv2json.rb:9:in
glob'__bind_1269015901_504391' ./test/test_csv2json.rb:8:in
chdir'__bind_1269015901_504391' /usr/lib/ruby/gems/1.8/gems/shoulda-2.10.3/lib/shoulda/context.rb:362:in
call'1 tests, 1 assertions, 1 failures, 0 errors
rake aborted!
Command failed with status (1): [/usr/bin/ruby1.8 -I"lib:lib:test" "/usr/li...]
(See full trace by running task with --trace)
Hey Folks,
Running ubuntu 12.04. needed to do the following
$sudo apt-get install ruby-dev
Then, from the other depency issue listed
$sudo gem install orderedhash
For those of us NOT ruby developers some simple docs listing deps would be welcome.
Thanks for the tool
sudo gem install csv2json -v 0.3.0
csv2json input.csv
/usr/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require': cannot load such file -- orderedhash (LoadError)
from /usr/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /var/lib/gems/2.1.0/gems/csv2json-0.3.0/lib/csv2json.rb:4:in `<top (required)>'
from /usr/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /usr/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /var/lib/gems/2.1.0/gems/csv2json-0.3.0/bin/csv2json:6:in `<top (required)>'
from /usr/local/bin/csv2json:23:in `load'
from /usr/local/bin/csv2json:23:in `<main>'
I tried using csv2json, here is what i get:
/usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require': cannot load such file -- orderedhash (LoadError)
from /usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from /var/lib/gems/1.9.1/gems/csv2json-0.3.0/lib/csv2json.rb:4:in `<top (required)>'
from /usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from /usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from /var/lib/gems/1.9.1/gems/csv2json-0.3.0/bin/csv2json:6:in `<top (required)>'
from /usr/local/bin/csv2json:23:in `load'
from /usr/local/bin/csv2json:23:in `<main>'
seems like a missing dependency to me, but im no rubyist =/ any ideas?
Received following error when running the example file.csv with csv2json-0.2.0 running on Ruby 1.9.3-p125
csv2json file.csv > file.json
/.rvm/gems/ruby-1.9.3-p125/gems/csv2json-0.2.0/lib/csv2json.rb:17:in initialize': wrong number of arguments(2 for 0) (ArgumentError) from /.rvm/gems/ruby-1.9.3-p125/gems/csv2json-0.2.0/lib/csv2json.rb:17:in
new'
from /.rvm/gems/ruby-1.9.3-p125/gems/csv2json-0.2.0/lib/csv2json.rb:17:in parse' from /.rvm/gems/ruby-1.9.3-p125/gems/csv2json-0.2.0/bin/csv2json:62:in
module:CSV2JSONRunner'
from /.rvm/gems/ruby-1.9.3-p125/gems/csv2json-0.2.0/bin/csv2json:8:in <top (required)>' from /.rvm/gems/ruby-1.9.3-p125/bin/csv2json:19:in
load'
from /.rvm/gems/ruby-1.9.3-p125/bin/csv2json:19:in `
Trying to parse a German csv file with Umlauts (ä, ö, ü) and ';' as delimiter (specified by using -s option) in it and got "invalid byte sequence in UTF-8 (ArgumentError)"
This doesn't work although it should according to the documentation:
`cat test.csv | csv2json``
I was getting an encoding error with a certain csv file "invalid byte sequence in UTF-8". Adding ":ISO-8859-1" when opening the file fixed my problem
if ARGV.size > 0
IN = File.open(ARGV[0], "r:ISO-8859-1")
I have no real issue, but just wanted to mention that you already support a configuration where you keep the csv-headers in a separate file from the data (e.g. headers.csv), which often happens when the csv-generator does not include the headers in the csv-output.
By using a command line script like:
csv2json headers.csv file.csv > file.json
all works great.
You may want to mention that available option to your readme.
Thanks for the command line tool - life saver!
-Frank.
Is it possible that you could add support for the compressed JSON format?
I ran a 22 MB CSV through this today and the output was 90MB, With compressed JSON it would have been about 32MB
Hi,
I got an error, any idea?
$ json2csv 1.json
/usr/lib/ruby/1.8/csv.rb:326:in initialize': can't convert Hash into String (TypeError) from /usr/lib/ruby/1.8/csv.rb:326:in
open'
from /usr/lib/ruby/1.8/csv.rb:326:in open_writer' from /usr/lib/ruby/1.8/csv.rb:111:in
generate'
from /usr/local/bin/../lib/json2csv.rb:15:in `parse'
from /usr/local/bin/json2csv:69
the json file is:
[
{
"thumbwidth": 75,
"imgsrc": "paris_01.jpg",
"thumbsrc": "paris_01.jpg",
"height": 262,
"imgpath": "images/",
"thumbheight": 56,
"thumbpath": "thumbnails/",
"width": 350
},
{
"thumbwidth": 75,
"imgsrc": "paris_02.jpg",
"thumbsrc": "paris_02.jpg",
"height": 350,
"imgpath": "images/",
"thumbheight": 56,
"thumbpath": "thumbnails/",
"width": 262
}
]
Also it seems the json2csv is not in the Ruby gem package.
$ csv2json file.csv > file.json
/data/rvm/gems/ruby-1.9.3-p545/gems/csv2json-0.2.0/lib/csv2json.rb:17:in initialize': wrong number of arguments(2 for 0) (ArgumentError) from /data/rvm/gems/ruby-1.9.3-p545/gems/csv2json-0.2.0/lib/csv2json.rb:17:in
new'
from /data/rvm/gems/ruby-1.9.3-p545/gems/csv2json-0.2.0/lib/csv2json.rb:17:in parse' from /data/rvm/gems/ruby-1.9.3-p545/gems/csv2json-0.2.0/bin/csv2json:62:in
module:CSV2JSONRunner'
from /data/rvm/gems/ruby-1.9.3-p545/gems/csv2json-0.2.0/bin/csv2json:8:in <top (required)>' from /data/rvm/gems/ruby-1.9.3-p545/bin/csv2json:23:in
load'
from /data/rvm/gems/ruby-1.9.3-p545/bin/csv2json:23:in <main>' from /data/rvm/gems/ruby-1.9.3-p545/bin/ruby_executable_hooks:15:in
eval'
from /data/rvm/gems/ruby-1.9.3-p545/bin/ruby_executable_hooks:15:in `
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.