File tree 2 files changed +11
-1
lines changed
2 files changed +11
-1
lines changed Original file line number Diff line number Diff line change @@ -80,7 +80,7 @@ def join(join_path)
80
80
81
81
def on ( obj_or_str , opts = { } )
82
82
a = enum_on ( obj_or_str ) . to_a
83
- if opts [ : symbolize_keys]
83
+ if symbolize_keys? ( opts )
84
84
a . map! do |e |
85
85
e . each_with_object ( { } ) { |( k , v ) , memo | memo [ k . to_sym ] = v ; }
86
86
end
@@ -153,4 +153,8 @@ def set_max_nesting
153
153
return unless @opts [ :max_nesting ] . is_a? ( Integer ) && @opts [ :max_nesting ] > MAX_NESTING_ALLOWED
154
154
@opts [ :max_nesting ] = false
155
155
end
156
+
157
+ def symbolize_keys? ( opts )
158
+ opts . fetch ( :symbolize_keys , @opts &.dig ( :symbolize_keys ) )
159
+ end
156
160
end
Original file line number Diff line number Diff line change @@ -1312,4 +1312,10 @@ def test_extractore_with_dollar_key
1312
1312
assert_equal [ "success" ] , JsonPath . on ( json , "$.test.$" )
1313
1313
assert_equal [ "123" ] , JsonPath . on ( json , "$.test.a" )
1314
1314
end
1315
+
1316
+ def test_symbolize_key
1317
+ data = { "store" => { "book" => [ { "category" => "test" } ] } }
1318
+ assert_equal [ { "category" : "reference" } ] , JsonPath . new ( '$..book[0]' , symbolize_keys : true ) . on ( data )
1319
+ assert_equal [ { "category" : "reference" } ] , JsonPath . new ( '$..book[0]' ) . on ( data , symbolize_keys : true )
1320
+ end
1315
1321
end
You can’t perform that action at this time.
0 commit comments