jsonpath 0.9.6 → 0.9.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/jsonpath.rb +8 -2
- data/lib/jsonpath/version.rb +1 -1
- data/test/test_jsonpath.rb +43 -0
- 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: 78e6fd3aa1c1d43001e53b13939d06e137441a52
|
4
|
+
data.tar.gz: 8d92b85875c0eddbb9f7c2997b21adcee58bcded
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 488e03a62223442af4449f9c237767e31a7f0044f228049884916bd92e283a4c5efb22c8f7e1800726dc16cf60f5c7801a5788a4b847150b7dc0794244cc41a1
|
7
|
+
data.tar.gz: 4a5ab8b934507c86bb7591bf2e894eb8084818d9216bae696b094452be1b8e92f270b3b903b711f6b5a82f6903dd1a267ea868398ad21ca4d1c28a21e71ba0c4
|
data/lib/jsonpath.rb
CHANGED
@@ -65,8 +65,14 @@ class JsonPath
|
|
65
65
|
res
|
66
66
|
end
|
67
67
|
|
68
|
-
def on(obj_or_str)
|
69
|
-
enum_on(obj_or_str).to_a
|
68
|
+
def on(obj_or_str, opts = {})
|
69
|
+
a = enum_on(obj_or_str).to_a
|
70
|
+
if opts[:symbolize_keys]
|
71
|
+
a.map! do |e|
|
72
|
+
e.inject({}) { |memo, (k, v)| memo[k.to_sym] = v; memo }
|
73
|
+
end
|
74
|
+
end
|
75
|
+
a
|
70
76
|
end
|
71
77
|
|
72
78
|
def first(obj_or_str, *args)
|
data/lib/jsonpath/version.rb
CHANGED
data/test/test_jsonpath.rb
CHANGED
@@ -610,6 +610,49 @@ class TestJsonpath < MiniTest::Unit::TestCase
|
|
610
610
|
assert_equal ['data'], JsonPath.new("$.{data}").on(data)
|
611
611
|
end
|
612
612
|
|
613
|
+
def test_symbolize
|
614
|
+
data = '
|
615
|
+
{
|
616
|
+
"store": {
|
617
|
+
"bicycle": {
|
618
|
+
"price": 19.95,
|
619
|
+
"color": "red"
|
620
|
+
},
|
621
|
+
"book": [
|
622
|
+
{
|
623
|
+
"price": 8.95,
|
624
|
+
"category": "reference",
|
625
|
+
"title": "Sayings of the Century",
|
626
|
+
"author": "Nigel Rees"
|
627
|
+
},
|
628
|
+
{
|
629
|
+
"price": 12.99,
|
630
|
+
"category": "fiction",
|
631
|
+
"title": "Sword of Honour",
|
632
|
+
"author": "Evelyn Waugh"
|
633
|
+
},
|
634
|
+
{
|
635
|
+
"price": 8.99,
|
636
|
+
"category": "fiction",
|
637
|
+
"isbn": "0-553-21311-3",
|
638
|
+
"title": "Moby Dick",
|
639
|
+
"author": "Herman Melville",
|
640
|
+
"color": "blue"
|
641
|
+
},
|
642
|
+
{
|
643
|
+
"price": 22.99,
|
644
|
+
"category": "fiction",
|
645
|
+
"isbn": "0-395-19395-8",
|
646
|
+
"title": "The Lord of the Rings",
|
647
|
+
"author": "Tolkien"
|
648
|
+
}
|
649
|
+
]
|
650
|
+
}
|
651
|
+
}
|
652
|
+
'
|
653
|
+
assert_equal [{:price=>8.95, :category=>"reference", :title=>"Sayings of the Century", :author=>"Nigel Rees"}, {:price=>8.99, :category=>"fiction", :isbn=>"0-553-21311-3", :title=>"Moby Dick", :author=>"Herman Melville", :color=>"blue"}], JsonPath.new('$..book[::2]').on(data, {symbolize_keys: true})
|
654
|
+
end
|
655
|
+
|
613
656
|
def test_changed
|
614
657
|
json =
|
615
658
|
{
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jsonpath
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joshua Hull
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2018-
|
12
|
+
date: 2018-12-03 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: multi_json
|