我需要找到某个哈希元素,其中一个键等于某个值。我尝试了很多方法,但似乎无法用jsonpath
gem 弄清楚。
需要在tire
哪里获取标签grip == 'bad'
require "jsonpath"
hash = {
:id => 1,
:cars => [
{:id => 1, :tire => {:grip => "good", :color => "black"}},
{:id => 2, :tire => {:grip => "bad", :color => "red"}},
{:id => 3, :tire => {:grip => "good", :color => "green"}}
]
}
puts JsonPath.on(hash, "$..tire[?(@['grip'] == 'bad')]").inspect
没结果。