json2yaml 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +10 -0
- data/bin/json2yaml +1 -1
- data/bin/yaml2json +1 -1
- data/lib/json2yaml.rb +14 -6
- data/lib/json2yaml/version.rb +1 -1
- data/spec/fixtures/test1.json +2 -0
- data/spec/fixtures/test1.yaml +5 -0
- data/spec/fixtures/test2.json +1 -0
- data/spec/fixtures/test2.yaml +4 -0
- data/spec/json2yaml_spec.rb +38 -4
- metadata +10 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f0c939abcc658d8470f0099f083631effed64548
|
4
|
+
data.tar.gz: 130fd19abd47da39896cd0c0564386cb572729be
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e7134526de4f9ab1e2d47a3b316807e6b3f19e110cc698bfb5e016663c1bf7fe5df199229a8114ecbf82db19de488ed59b12e739c292b110dd3cd6c78586ffa2
|
7
|
+
data.tar.gz: 9177b778c9cff036305864acde21a862a28477c0d54f16813fe0594f6323c34235adc3ca2d3b7341f53d00e85214c53d0e520e34a4adf867e5fc4b51cfc431e3
|
data/README.md
CHANGED
@@ -13,6 +13,8 @@ Convert between JSON and YAML in CLI
|
|
13
13
|
|
14
14
|
Now, you can use `json2yaml` and `yaml2json`
|
15
15
|
|
16
|
+
### Read from STDIN
|
17
|
+
|
16
18
|
```
|
17
19
|
$ echo '{ "a" : 123 }' | json2yaml
|
18
20
|
#=>
|
@@ -29,6 +31,14 @@ $ cat bar.yml | yaml2json > bar.json
|
|
29
31
|
|
30
32
|
```
|
31
33
|
|
34
|
+
### Read from files
|
35
|
+
|
36
|
+
```
|
37
|
+
$ json2yaml log1.json log2.json > log.yaml
|
38
|
+
|
39
|
+
$ yaml2json log1.yaml log2.yaml > log.json
|
40
|
+
```
|
41
|
+
|
32
42
|
## Contributing
|
33
43
|
|
34
44
|
1. Fork it
|
data/bin/json2yaml
CHANGED
data/bin/yaml2json
CHANGED
data/lib/json2yaml.rb
CHANGED
@@ -3,18 +3,26 @@ require 'yajl/json_gem'
|
|
3
3
|
require 'yaml'
|
4
4
|
|
5
5
|
module Json2yaml
|
6
|
-
def self.to_yaml(json_stream)
|
6
|
+
def self.to_yaml(json_stream, argv)
|
7
|
+
inputs = argv.empty? ? [json_stream] : argv.map{|file| open(file) }
|
8
|
+
|
7
9
|
Enumerator.new do |yielder|
|
8
|
-
|
9
|
-
|
10
|
+
inputs.each do |input|
|
11
|
+
Yajl::Parser.new.parse(input) do |d|
|
12
|
+
yielder.yield d.to_yaml
|
13
|
+
end
|
10
14
|
end
|
11
15
|
end
|
12
16
|
end
|
13
17
|
|
14
|
-
def self.to_json(yaml_stream)
|
18
|
+
def self.to_json(yaml_stream, argv)
|
19
|
+
inputs = argv.empty? ? [yaml_stream] : argv.map{|file| open(file) }
|
20
|
+
|
15
21
|
Enumerator.new do |yielder|
|
16
|
-
|
17
|
-
|
22
|
+
inputs.each do |input|
|
23
|
+
YAML.load_stream(input) do |d|
|
24
|
+
yielder.yield d.to_json + "\n"
|
25
|
+
end
|
18
26
|
end
|
19
27
|
end
|
20
28
|
end
|
data/lib/json2yaml/version.rb
CHANGED
@@ -0,0 +1 @@
|
|
1
|
+
[1,true,false,null]
|
data/spec/json2yaml_spec.rb
CHANGED
@@ -1,17 +1,19 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Json2yaml do
|
4
|
+
FIXTURES_DIR = File.join(File.dirname(__FILE__), 'fixtures')
|
5
|
+
|
4
6
|
context "with single data" do
|
5
7
|
let(:json_str) { "{\"a\":\"b\"}\n" }
|
6
8
|
let(:yaml_str) { "---\na: b\n" }
|
7
9
|
let(:json_io) { StringIO.new(json_str, "r") }
|
8
10
|
let(:yaml_io) { StringIO.new(yaml_str, "r") }
|
9
11
|
context '.to_json' do
|
10
|
-
it { expect(Json2yaml.to_yaml(json_io).reduce(&:+)).to eq(yaml_str) }
|
12
|
+
it { expect(Json2yaml.to_yaml(json_io, []).reduce(&:+)).to eq(yaml_str) }
|
11
13
|
end
|
12
14
|
|
13
15
|
context '.to_yaml' do
|
14
|
-
it { expect(Json2yaml.to_json(yaml_io).reduce(&:+)).to eq(json_str) }
|
16
|
+
it { expect(Json2yaml.to_json(yaml_io, []).reduce(&:+)).to eq(json_str) }
|
15
17
|
end
|
16
18
|
end
|
17
19
|
|
@@ -21,11 +23,43 @@ describe Json2yaml do
|
|
21
23
|
let(:json_io) { StringIO.new(json_str, "r") }
|
22
24
|
let(:yaml_io) { StringIO.new(yaml_str, "r") }
|
23
25
|
context '.to_json' do
|
24
|
-
it { expect(Json2yaml.to_yaml(json_io).reduce(&:+)).to eq(yaml_str) }
|
26
|
+
it { expect(Json2yaml.to_yaml(json_io, []).reduce(&:+)).to eq(yaml_str) }
|
25
27
|
end
|
26
28
|
|
27
29
|
context '.to_yaml' do
|
28
|
-
it { expect(Json2yaml.to_json(yaml_io).reduce(&:+)).to eq(json_str) }
|
30
|
+
it { expect(Json2yaml.to_json(yaml_io, []).reduce(&:+)).to eq(json_str) }
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
context "load by arguments" do
|
35
|
+
let(:test1_json_as_yaml) { "---\nfoo: bar\nfoobar: baz\n---\nqux: quux\n" }
|
36
|
+
let(:test2_json_as_yaml) { "---\n- 1\n- true\n- false\n- \n" }
|
37
|
+
let(:test1_yaml_as_json) { "{\"foo\":\"bar\",\"foobar\":\"baz\"}\n{\"qux\":\"quux\"}\n" }
|
38
|
+
let(:test2_yaml_as_json) { "[1,true,false,null]\n" }
|
39
|
+
let(:empty_io) { StringIO.new }
|
40
|
+
|
41
|
+
context "with single argument" do
|
42
|
+
context '.to_json' do
|
43
|
+
let(:argv) { [File.join(FIXTURES_DIR, 'test1.yaml')] }
|
44
|
+
it { expect(Json2yaml.to_json(empty_io, argv).reduce(&:+)).to eq(test1_yaml_as_json) }
|
45
|
+
end
|
46
|
+
|
47
|
+
context '.to_yaml' do
|
48
|
+
let(:argv) { [File.join(FIXTURES_DIR, 'test1.json')] }
|
49
|
+
it { expect(Json2yaml.to_yaml(empty_io, argv).reduce(&:+)).to eq(test1_json_as_yaml) }
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
context "with multiple arguments" do
|
54
|
+
context '.to_json' do
|
55
|
+
let(:argv) { [File.join(FIXTURES_DIR, 'test1.yaml'), File.join(FIXTURES_DIR, 'test2.yaml')] }
|
56
|
+
it { expect(Json2yaml.to_json(empty_io, argv).reduce(&:+)).to eq(test1_yaml_as_json + test2_yaml_as_json) }
|
57
|
+
end
|
58
|
+
|
59
|
+
context '.to_yaml' do
|
60
|
+
let(:argv) { [File.join(FIXTURES_DIR, 'test1.json'), File.join(FIXTURES_DIR, 'test2.json')] }
|
61
|
+
it { expect(Json2yaml.to_yaml(empty_io, argv).reduce(&:+)).to eq(test1_json_as_yaml + test2_json_as_yaml) }
|
62
|
+
end
|
29
63
|
end
|
30
64
|
end
|
31
65
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: json2yaml
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- fukayatsu
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-11-
|
11
|
+
date: 2014-11-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: yajl-ruby
|
@@ -88,6 +88,10 @@ files:
|
|
88
88
|
- json2yaml.gemspec
|
89
89
|
- lib/json2yaml.rb
|
90
90
|
- lib/json2yaml/version.rb
|
91
|
+
- spec/fixtures/test1.json
|
92
|
+
- spec/fixtures/test1.yaml
|
93
|
+
- spec/fixtures/test2.json
|
94
|
+
- spec/fixtures/test2.yaml
|
91
95
|
- spec/json2yaml_spec.rb
|
92
96
|
- spec/spec_helper.rb
|
93
97
|
homepage: https://github.com/fukayatsu/json2yaml
|
@@ -115,6 +119,10 @@ signing_key:
|
|
115
119
|
specification_version: 4
|
116
120
|
summary: Convert between JSON and YAML in CLI
|
117
121
|
test_files:
|
122
|
+
- spec/fixtures/test1.json
|
123
|
+
- spec/fixtures/test1.yaml
|
124
|
+
- spec/fixtures/test2.json
|
125
|
+
- spec/fixtures/test2.yaml
|
118
126
|
- spec/json2yaml_spec.rb
|
119
127
|
- spec/spec_helper.rb
|
120
128
|
has_rdoc:
|