csv_to_json 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/bin/csv_to_json +49 -0
  3. metadata +72 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 654bceaca1a8545da526ddcbb2998875b0ef4187d8598ae3b2b6a15563f02393
4
+ data.tar.gz: 9c18082d75484430aaf3486962cf0b4ea5225e8d53200839485b7dd6d10a6f51
5
+ SHA512:
6
+ metadata.gz: bedc0c7ef7e5837d88bb1561cae37ff2c73a7caa1d8af2c0ebe59349007890e616240571618c1c0b634458f01dbf07cc68acde362140bde39ed35e5083b606f1
7
+ data.tar.gz: ecfebfc4c16d47cc8a611089c761cd5fb8387fe6923ae4ab4f1fe0fa5c64f4e2f2270bab18c95673ad04ba1b9ad5498a8d34559622efe36d081a4be166114399
@@ -0,0 +1,49 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'csv'
5
+ require 'json'
6
+ require 'optparse'
7
+
8
+ options = {
9
+ headers: [],
10
+ converters: [],
11
+ stream: false
12
+ }
13
+
14
+ OptionParser.new do |opts|
15
+ opts.banner = "Usage: #{$PROGRAM_NAME} [options] [FILE]"
16
+
17
+ opts.on('--headers=x,y,z', Array) do |headers|
18
+ options[:headers] = headers
19
+ end
20
+
21
+ opts.on('--converters=x,y,z', Array) do |converters|
22
+ options[:converters] = converters.map!(&:to_sym)
23
+ end
24
+
25
+ opts.on('--[no-]stream') do |stream|
26
+ options[:stream] = stream
27
+ end
28
+
29
+ opts.on('-h', '--help', 'Prints this help') do
30
+ puts opts
31
+ exit
32
+ end
33
+ end.parse!
34
+ print '[' unless options[:stream]
35
+ first_iter = true
36
+ CSV.new(
37
+ ARGF,
38
+ headers: options[:headers].empty? ? true : options[:headers],
39
+ converters: options[:converters]
40
+ ).each do |row|
41
+ json = row.to_hash.to_json
42
+ if options[:stream]
43
+ puts json
44
+ else
45
+ first_iter ? first_iter = false : print(',')
46
+ print json
47
+ end
48
+ end
49
+ print ']' unless options[:stream]
metadata ADDED
@@ -0,0 +1,72 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: csv_to_json
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Jian Weihang
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-01-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.17'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.17'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '13.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '13.0'
41
+ description: A Command-Line Tool converting CSV to JSON
42
+ email: tonytonyjan@gmail.com
43
+ executables:
44
+ - csv_to_json
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - bin/csv_to_json
49
+ homepage: https://github.com/tonytonyjan/csv_to_json
50
+ licenses:
51
+ - MIT
52
+ metadata: {}
53
+ post_install_message:
54
+ rdoc_options: []
55
+ require_paths:
56
+ - lib
57
+ required_ruby_version: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ required_rubygems_version: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ requirements: []
68
+ rubygems_version: 3.0.3
69
+ signing_key:
70
+ specification_version: 4
71
+ summary: A Command-Line Tool converting CSV to JSON
72
+ test_files: []