Module: JMESPath

Defined in:
lib/jmespath.rb,
lib/jmespath/util.rb,
lib/jmespath/lexer.rb,
lib/jmespath/nodes.rb,
lib/jmespath/token.rb,
lib/jmespath/errors.rb,
lib/jmespath/parser.rb,
lib/jmespath/runtime.rb,
lib/jmespath/version.rb,
lib/jmespath/nodes/or.rb,
lib/jmespath/nodes/and.rb,
lib/jmespath/nodes/not.rb,
lib/jmespath/nodes/pipe.rb,
lib/jmespath/nodes/field.rb,
lib/jmespath/nodes/index.rb,
lib/jmespath/nodes/slice.rb,
lib/jmespath/token_stream.rb,
lib/jmespath/nodes/current.rb,
lib/jmespath/nodes/flatten.rb,
lib/jmespath/nodes/literal.rb,
lib/jmespath/caching_parser.rb,
lib/jmespath/nodes/function.rb,
lib/jmespath/nodes/condition.rb,
lib/jmespath/nodes/comparator.rb,
lib/jmespath/nodes/expression.rb,
lib/jmespath/nodes/projection.rb,
lib/jmespath/nodes/subexpression.rb,
lib/jmespath/nodes/multi_select_hash.rb,
lib/jmespath/nodes/multi_select_list.rb

Defined Under Namespace

Modules: Errors, Nodes, Util Classes: CachingParser, Lexer, Parser, Runtime, Token, TokenStream

Constant Summary collapse

VERSION =
'1.4.0'

Class Method Summary collapse

Class Method Details

.load_json(path) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


36
37
38
# File 'lib/jmespath.rb', line 36

def load_json(path)
  JSON.load(File.open(path, 'r', encoding: 'UTF-8') { |f| f.read })
end

.search(expression, data, runtime_options = {}) ⇒ Mixed?


25
26
27
28
29
30
31
32
33
# File 'lib/jmespath.rb', line 25

def search(expression, data, runtime_options = {})
  data = case data
    when Hash, Struct then data # check for most common case first
    when Pathname then load_json(data)
    when IO, StringIO then JSON.load(data.read)
    else data
    end
  Runtime.new(runtime_options).search(expression, data)
end