Krikri::JMESPath
A JMESPath query engine backing the json_query filter (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
&exprfor 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 (Ansible's json_query fails the task on an
unparseable expression too).
Constants
Class methods
Applies a JMESPath expression to data, returning the result.
Applies a JMESPath expression to data with the json_query
filter's task-failure semantics: any engine error (parse or
evaluation) is re-raised wrapped in the filter-style message. This
is the single shared wrapper both dispatch paths go through - the
hand-rolled FilterEngine calls it directly on its own JSON::Any
values (zero conversion), and the native Crinja.filter(:json_query)
registration (src/krikri/jinja_filters.cr) calls it after bridging
its Crinja::Value target in, so the wrapped error text has exactly
one source.
Nested types
- Krikri::JMESPath::AndOp
- Krikri::JMESPath::Comparison
- Krikri::JMESPath::Current
- Krikri::JMESPath::Error
- Krikri::JMESPath::Evaluator
- Krikri::JMESPath::ExpRef
- Krikri::JMESPath::Field
- Krikri::JMESPath::Filter
- Krikri::JMESPath::Flatten
- Krikri::JMESPath::FunctionCall
- Krikri::JMESPath::Index
- Krikri::JMESPath::Literal
- Krikri::JMESPath::MultiSelectHash
- Krikri::JMESPath::MultiSelectList
- Krikri::JMESPath::Node
- Krikri::JMESPath::NotOp
- Krikri::JMESPath::OrOp
- Krikri::JMESPath::Parser
- Krikri::JMESPath::Pipe
- Krikri::JMESPath::Slice
- Krikri::JMESPath::SubExpression
- Krikri::JMESPath::Token
- Krikri::JMESPath::TokenKind
- Krikri::JMESPath::Tokenizer
- Krikri::JMESPath::Wildcard