json_paths 0.0.1 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 55d10e0128711f471a1b1c7216c20e8127cfe229
4
- data.tar.gz: 8947019433897eb003b6a3f2493d0952acd7005d
3
+ metadata.gz: 82f2a9c9a57fa7ca49cf824acd9468fe1b0374c9
4
+ data.tar.gz: 176584bdd7962d35e201867ace997c3931c3e9c6
5
5
  SHA512:
6
- metadata.gz: e3a1dec3d6081a13a6cde313a85e972726f43700287346e2affa199ef23932368ffd34909ab34b5e2f5f47cef5f2b0fa3e6eb9a6bc7b08871b330851c1550a95
7
- data.tar.gz: 9836130b466f1927c227764228097d149b327203b73d08b08f2d78ec633f674786ab560553c414dd53240e200925bb666273a78939dcb9370965198d5a0e0a27
6
+ metadata.gz: b7271ebdd4820f6e192b21d2ad966921fd1bcdfa53de52584f05e322662c5cc8735304482f66dfd3cdf6abb087a95ff24b710cd56ed0a13fe7b996c5cb797f91
7
+ data.tar.gz: 11d70866d9e4e9638e6a7b8ec5bf25947d7c13af7c3c2162f2813832fbb0a35a2c3543c50219c937a567c721e31e43db3392b14229d19747d63b743c26938f7e
@@ -1,3 +1,3 @@
1
1
  class JsonPaths
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.3"
3
3
  end
data/lib/json_paths.rb CHANGED
@@ -22,10 +22,10 @@ class JsonPaths
22
22
  paths = []
23
23
 
24
24
  parsed_json.each_key do |key|
25
- paths << key_to_path(parsed_json, key).map { |k| "$." + k.to_s}
25
+ paths << key_to_path(parsed_json, key)
26
26
  end
27
27
 
28
- paths.flatten
28
+ paths.flatten.map { |path| "$." + path }
29
29
  end
30
30
 
31
31
  def key_to_path(hash, key)
@@ -33,9 +33,9 @@ class JsonPaths
33
33
  value = hash[key]
34
34
 
35
35
  if value.respond_to?(:keys)
36
- value.each_key do |k|
37
- paths_for_key << key_to_path(value, k).map { |ktp| [key.to_s, ktp].flatten }
38
- end
36
+ paths_for_key << value.each_key do |k|
37
+ key_to_path(value, k).map { |ktp| key + "." + ktp }
38
+ end.flatten
39
39
  elsif value.respond_to?(:each_with_index)
40
40
  value.each_with_index do |v,i|
41
41
  paths_for_key << JsonPaths.new(v.to_json).paths.map do |j|
@@ -43,9 +43,9 @@ class JsonPaths
43
43
  end
44
44
  end
45
45
  else
46
- paths_for_key = [key.to_s]
46
+ paths_for_key << key.to_s
47
47
  end
48
48
 
49
- Array(paths_for_key.map { |p| Array(p).join('.') })
49
+ paths_for_key
50
50
  end
51
51
  end
@@ -4,20 +4,22 @@ describe JsonPaths do
4
4
  let(:json) do
5
5
  <<-EOF
6
6
  {
7
- "a": {
8
- "b": {
9
- "c": 1
7
+ "a": [
8
+ {
9
+ "b": 1,
10
+ "c": 2
10
11
  },
11
- "d": 2,
12
- "e": [{"f": 3}]
13
- }
12
+ {
13
+ "d": 3
14
+ }
15
+ ]
14
16
  }
15
17
  EOF
16
18
  end
17
19
 
18
20
  subject { JsonPaths.new(json) }
19
21
 
20
- specify { expect(subject.paths).to include("$.a.b.c") }
21
- specify { expect(subject.paths).to include("$.a.d") }
22
- specify { expect(subject.paths).to include("$.a.e[0].f") }
22
+ specify { expect(subject.paths).to include("$.a[0].b") }
23
+ specify { expect(subject.paths).to include("$.a[0].c") }
24
+ specify { expect(subject.paths).to include("$.a[1].d") }
23
25
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: json_paths
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Pruitt