module

Krikri::JMESPath

A JMESPath query engine backing the json_query filter (real Ansible's own filter from community.general, commonly reachable as a bare name). Implemented here rather than vendored: the Crystal ecosystem has no maintained JMESPath shard, so this is a from-scratch recursive-descent parser + evaluator over JSON::Any.

Supported grammar (per the JMESPath specification):

  • field access (foo, foo.bar, quoted "a-b")
  • the current node @ and JSON literals in backticks (`42`)
  • index [0] (negative ok) and slices [1:10:2]
  • wildcards [*]/.*, list flattening [], filters [?expr]
  • multi-select lists [a, b] and hashes {k: v}
  • pipe |, and/or/not (&&, ||, !), comparisons (==, !=, <, <=, >, >=)
  • expression references &expr for the by/map functions
  • functions: length, keys, values, type, not_null, to_string, to_number, to_array, abs, ceil, floor, avg, sum, min, max, min_by, max_by, sort, sort_by, reverse, join, contains, starts_with, ends_with, map, merge

Projection semantics follow the spec's observable behavior: a wildcard/flatten/filter produces a projection, and a field access / index / slice applied to a projection maps over its elements, dropping null results. Syntactically invalid expressions raise JMESPath::Error (real Ansible's json_query fails the task on an unparseable expression too).

Constants

NULL = JSON::Any.new(nil)

Class methods

evaluate(expression : String, data : JSON::Any) : JSON::Any

Applies a JMESPath expression to data, returning the result.

Source

Nested types