jrq 0.1.4 → 0.1.5
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 +100 -10
- data/lib/jrq.rb +4 -1
- data/lib/jrq/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7e977293feceafe2cf96776d29cf80a25f705b88
|
4
|
+
data.tar.gz: f035ec0576334a3d30d4e7167217996981053137
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 45000c9249d529677a6af8f978d0da35c0bcc7e3198fb392a5b030426f70c9afebce8a3ef8ab9a5c40b7a3da9bb0aaa1d9eadf03542949d666d4d6a9df414f08
|
7
|
+
data.tar.gz: cbb19d2af1cce0501e2e8e4cd9ad01ed3d7d0a3a5ddfd22d730d0a6b33ef4eacf365a5bb50371369a20b4614bc25c1d9cfd0c3f6e6b782d7675ed69187c29d40
|
data/README.md
CHANGED
@@ -1,4 +1,11 @@
|
|
1
|
-
#
|
1
|
+
# jrq
|
2
|
+
|
3
|
+
jrq is a CLI JSON processor for Rubyists. jrq enable you to filter/map/reduce JSON without studying new syntax.
|
4
|
+
|
5
|
+
```
|
6
|
+
$ echo '{"foo": [1, 2, 3], "bar": 100 }' \
|
7
|
+
| jrq '_.foo.reduce(&:+) * _.bar' # => 600
|
8
|
+
```
|
2
9
|
|
3
10
|
## Installation
|
4
11
|
|
@@ -18,11 +25,90 @@ Or install it yourself as:
|
|
18
25
|
|
19
26
|
## Usage
|
20
27
|
|
21
|
-
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
28
|
+
JSON data from STDIN will be parsed and passed as `_` variable. Because jrq just evaling given string in the context of Ruby, actually it's almost same as doing like `cat a.json | ruby -rjson -e "JSON.load(STDIN)['foo']"`. Here are some samples below:
|
29
|
+
|
30
|
+
`_` is a Hash, so `_.keys` would be nice place to start with.
|
31
|
+
|
32
|
+
```
|
33
|
+
$ aws ec2 describe-instances \
|
34
|
+
| jrq '_.keys'
|
35
|
+
[
|
36
|
+
"Reservations"
|
37
|
+
]
|
38
|
+
```
|
39
|
+
|
40
|
+
jrq parses given JSON with [Hashie::Mash](https://github.com/intridea/hashie#mash), so you can access json fields with dot(`.`) like Ruby's method access.
|
41
|
+
|
42
|
+
```
|
43
|
+
$ aws ec2 describe-instances \
|
44
|
+
| jrq '_.Reservations.class'
|
45
|
+
Array
|
46
|
+
```
|
47
|
+
|
48
|
+
Then digging deeper...
|
49
|
+
|
50
|
+
```
|
51
|
+
$ aws ec2 describe-instances \
|
52
|
+
| jrq -r '_.Reservations.map{|r| r.keys }.flatten.uniq'
|
53
|
+
[
|
54
|
+
"OwnerId",
|
55
|
+
"ReservationId",
|
56
|
+
"Groups",
|
57
|
+
"Instances",
|
58
|
+
"RequesterId"
|
59
|
+
]
|
60
|
+
```
|
61
|
+
|
62
|
+
... to get information you need.
|
63
|
+
|
64
|
+
```
|
65
|
+
$ aws ec2 describe-instances \
|
66
|
+
| jrq 'ins = _.Reservations.first.Instances.first;
|
67
|
+
[ins.InstanceId, ins.VpcId, ins.SubnetId, ins.PrivateIpAddress]'
|
68
|
+
[
|
69
|
+
"i-aaaaaaaa",
|
70
|
+
"vpc-5dxxxxx8",
|
71
|
+
"subnet-a1xxxxx6",
|
72
|
+
"172.31.25.92"
|
73
|
+
]
|
74
|
+
```
|
75
|
+
|
76
|
+
```
|
77
|
+
$ aws ec2 describe-instances \
|
78
|
+
| jrq '_.Reservations.map{|r| r.Instances.map{|i| i.InstanceId } }.flatten'
|
79
|
+
[
|
80
|
+
"i-aaaaaaaa",
|
81
|
+
"i-bbbbbbbb",
|
82
|
+
"i-cccccccc",
|
83
|
+
"i-dddddddd",
|
84
|
+
]
|
85
|
+
```
|
86
|
+
|
87
|
+
With `-r` or `--raw` option, raw output would be displayed. It's suitable for passing to another program as input.
|
88
|
+
|
89
|
+
```
|
90
|
+
$ aws ec2 describe-instances \
|
91
|
+
| jrq -r '_.Reservations.map{|r| r.Instances.map{|i| i.InstanceId } }.flatten'
|
92
|
+
i-aaaaaaaa
|
93
|
+
i-bbbbbbbb
|
94
|
+
i-cccccccc
|
95
|
+
i-dddddddd
|
96
|
+
```
|
97
|
+
|
98
|
+
You can even require another Ruby library.
|
99
|
+
|
100
|
+
```
|
101
|
+
$ curl -s https://ip-ranges.amazonaws.com/ip-ranges.json \
|
102
|
+
| jrq 'require "ipaddr"; _.prefixes.select{|p| p.region == "ap-northeast-1" }.map{|p| IPAddr.new(p.ip_prefix).to_i.to_s(2) }'
|
103
|
+
|
104
|
+
[
|
105
|
+
"11011000000000000000000000000",
|
106
|
+
"101110001100111110000000000000",
|
107
|
+
"110100010001000000000000000000",
|
108
|
+
"110100010111000011110000000000",
|
109
|
+
"110100010111000101000000000000",
|
110
|
+
...
|
111
|
+
```
|
26
112
|
|
27
113
|
## Development
|
28
114
|
|
@@ -42,17 +128,21 @@ or
|
|
42
128
|
|
43
129
|
$ gem push jrq-x.y.z.gem
|
44
130
|
|
45
|
-
### Plan
|
131
|
+
### Plan & TODOs
|
46
132
|
|
47
133
|
- color
|
48
134
|
- launch REPL when STDIN isn't given
|
49
135
|
- jrq foo.json => also launch REPL
|
50
|
-
- (maybe) _ -> j ?
|
51
136
|
|
52
|
-
|
137
|
+
- prepare sample JSON data
|
138
|
+
- AWS ip-ranges.json
|
139
|
+
- CloudFormation Template
|
140
|
+
- ECS Task Definition
|
141
|
+
- JSON Schema / Swagger
|
53
142
|
|
54
|
-
|
143
|
+
## Contributing
|
55
144
|
|
145
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/memerelics/jrq/issues
|
56
146
|
|
57
147
|
## License
|
58
148
|
|
data/lib/jrq.rb
CHANGED
@@ -9,7 +9,10 @@ module Jrq
|
|
9
9
|
|
10
10
|
def run(args, opts)
|
11
11
|
_ = JSON.load(stdin)
|
12
|
-
_ =
|
12
|
+
_ = case _
|
13
|
+
when Hash then Hashie::Mash.new(_)
|
14
|
+
when Array then _.map{|obj| Hashie::Mash.new(obj) }
|
15
|
+
end
|
13
16
|
if args.length.zero?
|
14
17
|
display(_, opts)
|
15
18
|
else
|
data/lib/jrq/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jrq
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- memerelics
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-03
|
11
|
+
date: 2016-10-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: hashie
|