Method: Janeway.parse

Defined in:
lib/janeway.rb

.parse(query) ⇒ Janeway::AST::Query

Parse a JSONPath string into a Janeway::Query object.

This object can be combined with data to create Enumerators that apply the query to the data.

Use this method if you want to parse the query once and re-use it for multiple data sets.

Otherwise, use Janeway.enum_for to parse the query and pair it with data in a single step.

Examples:

Use a query to search several JSON files

results = []
query = Janeway.parse('$.store.books[? length(@.title) > 20]')
data_files.each do |path|
  data = JSON.parse File.read(path)
  results.concat query.enum_for(data).search
end

Parameters:

  • query (String)

    jsonpath query

Returns:

  • (Janeway::AST::Query)


53
54
55
# File 'lib/janeway.rb', line 53

def self.parse(query)
  Janeway::Parser.parse(query)
end