jsonpath 0.8.11 → 0.8.12
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/jsonpath/enumerable.rb +1 -2
- data/lib/jsonpath/parser.rb +4 -1
- data/lib/jsonpath/version.rb +1 -1
- data/test/test_jsonpath.rb +93 -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: 9338212edfe2ba8589ef826b3443fb7dcfdc3112
|
4
|
+
data.tar.gz: b5e09641428a77416aa455ec0450f0730abe86b4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ce08bd8da4e3240d613d589400d32219563c76afb376e46967258afb6000e00a924e8480ee2f934da4696ef2b34eb52f1409a5b8ecc0b80ed523d6f44dc990b5
|
7
|
+
data.tar.gz: ccbbce4a9e02ad37c2f70ffa16a40a6667d3df00a57be835493589b3c0903efd0d8105e9e56032b2d232235b6d59955dff6281e02f718ffd528abeb8871a8b1c
|
data/lib/jsonpath/enumerable.rb
CHANGED
@@ -111,8 +111,7 @@ class JsonPath
|
|
111
111
|
return nil unless @_current_node
|
112
112
|
|
113
113
|
identifiers = /@?((?<!\d)\.(?!\d)(\w+))+/.match(exp)
|
114
|
-
unless identifiers.nil? ||
|
115
|
-
@_current_node.methods.include?(identifiers[2].to_sym)
|
114
|
+
unless identifiers.nil? || @_current_node.methods.include?(identifiers[2].to_sym)
|
116
115
|
exp_to_eval = exp.dup
|
117
116
|
exp_to_eval[identifiers[0]] = identifiers[0].split('.').map do |el|
|
118
117
|
el == '@' ? '@' : "['#{el}']"
|
data/lib/jsonpath/parser.rb
CHANGED
@@ -45,12 +45,15 @@ class JsonPath
|
|
45
45
|
raise "Could not process symbol: #{t}"
|
46
46
|
end
|
47
47
|
end
|
48
|
+
|
48
49
|
el = dig(elements, @_current_node)
|
49
|
-
return false
|
50
|
+
return false if el.nil?
|
50
51
|
return true if operator.nil? && el
|
51
52
|
|
52
53
|
el = Float(el) rescue el
|
53
54
|
operand = Float(operand) rescue operand
|
55
|
+
operand = false if operand == 'false' && el == false
|
56
|
+
|
54
57
|
el.send(operator.strip, operand)
|
55
58
|
end
|
56
59
|
|
data/lib/jsonpath/version.rb
CHANGED
data/test/test_jsonpath.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'minitest/autorun'
|
2
2
|
require 'phocus'
|
3
3
|
require 'jsonpath'
|
4
|
+
require 'json'
|
4
5
|
|
5
6
|
class TestJsonpath < MiniTest::Unit::TestCase
|
6
7
|
def setup
|
@@ -368,6 +369,20 @@ class TestJsonpath < MiniTest::Unit::TestCase
|
|
368
369
|
assert_equal [{'number'=>'(492) 080-3961'}], JsonPath.new("$.data[?(@.number == '(492) 080-3961')]").on(data)
|
369
370
|
end
|
370
371
|
|
372
|
+
|
373
|
+
def test_boolean_parameter_value
|
374
|
+
data = {
|
375
|
+
'data' => [{
|
376
|
+
'isTrue' => true,
|
377
|
+
'name' => 'testname1',
|
378
|
+
},{
|
379
|
+
'isTrue' => false,
|
380
|
+
'name' => 'testname2',
|
381
|
+
}]
|
382
|
+
}
|
383
|
+
assert_equal [{"isTrue"=>true, "name"=>"testname1"}], JsonPath.new("$.data[?(@.isTrue)]").on(data)
|
384
|
+
end
|
385
|
+
|
371
386
|
def test_regex
|
372
387
|
assert_equal [], JsonPath.new('$..book[?(@.author =~ /herman/)]').on(@object)
|
373
388
|
assert_equal [
|
@@ -379,6 +394,84 @@ class TestJsonpath < MiniTest::Unit::TestCase
|
|
379
394
|
assert_equal ["asdf", "asdf2"], JsonPath.new("$.store.book..tags[?(@ =~ /asdf/)]").on(@object)
|
380
395
|
end
|
381
396
|
|
397
|
+
def test_regression_1
|
398
|
+
json = {
|
399
|
+
ok: true,
|
400
|
+
channels: [
|
401
|
+
{
|
402
|
+
id: 'C09C5GYHF',
|
403
|
+
name: 'general'
|
404
|
+
},
|
405
|
+
{
|
406
|
+
id: 'C09C598QL',
|
407
|
+
name: 'random'
|
408
|
+
}
|
409
|
+
]
|
410
|
+
}.to_json
|
411
|
+
|
412
|
+
assert_equal 'C09C5GYHF', JsonPath.on(json, "$..channels[?(@.name == 'general')].id")[0]
|
413
|
+
end
|
414
|
+
|
415
|
+
def test_regression_2
|
416
|
+
json = {
|
417
|
+
ok: true,
|
418
|
+
channels: [
|
419
|
+
{
|
420
|
+
id: 'C09C5GYHF',
|
421
|
+
name: 'general',
|
422
|
+
is_archived: false
|
423
|
+
},
|
424
|
+
{
|
425
|
+
id: 'C09C598QL',
|
426
|
+
name: 'random',
|
427
|
+
is_archived: true
|
428
|
+
}
|
429
|
+
]
|
430
|
+
}.to_json
|
431
|
+
|
432
|
+
assert_equal 'C09C5GYHF', JsonPath.on(json, "$..channels[?(@.is_archived == false)].id")[0]
|
433
|
+
end
|
434
|
+
|
435
|
+
def test_regression_3
|
436
|
+
json = {
|
437
|
+
ok: true,
|
438
|
+
channels: [
|
439
|
+
{
|
440
|
+
id: 'C09C5GYHF',
|
441
|
+
name: 'general',
|
442
|
+
is_archived: false
|
443
|
+
},
|
444
|
+
{
|
445
|
+
id: 'C09C598QL',
|
446
|
+
name: 'random',
|
447
|
+
is_archived: true
|
448
|
+
}
|
449
|
+
]
|
450
|
+
}.to_json
|
451
|
+
|
452
|
+
assert_equal 'C09C598QL', JsonPath.on(json, "$..channels[?(@.is_archived)].id")[0]
|
453
|
+
end
|
454
|
+
|
455
|
+
def test_regression_5
|
456
|
+
json = {
|
457
|
+
ok: true,
|
458
|
+
channels: [
|
459
|
+
{
|
460
|
+
id: 'C09C5GYHF',
|
461
|
+
name: 'general',
|
462
|
+
is_archived: 'false'
|
463
|
+
},
|
464
|
+
{
|
465
|
+
id: 'C09C598QL',
|
466
|
+
name: 'random',
|
467
|
+
is_archived: true
|
468
|
+
}
|
469
|
+
]
|
470
|
+
}.to_json
|
471
|
+
|
472
|
+
assert_equal 'C09C5GYHF', JsonPath.on(json, "$..channels[?(@.is_archived == 'false')].id")[0]
|
473
|
+
end
|
474
|
+
|
382
475
|
def example_object
|
383
476
|
{ 'store' => {
|
384
477
|
'book' => [
|
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.8.
|
4
|
+
version: 0.8.12
|
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-05-12 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: multi_json
|