Skip to content

Commit

Permalink
[ternary] supports ternary operator expressions
Browse files Browse the repository at this point in the history
  • Loading branch information
springcomp committed Jan 15, 2025
1 parent 0127b7e commit eec6d99
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions jmespath/visitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,17 @@ def visit_variable_ref(self, node, value):
except KeyError:
raise exceptions.UndefinedVariable(node['value'])

def visit_ternary_operator(self, node, value):
condition = node['children'][0]
evaluation = self.visit(condition, value)

if self._is_false(evaluation):
falsyNode = node['children'][2]
return self.visit(falsyNode, value)
else:
truthyNode = node['children'][1]
return self.visit(truthyNode, value)

def visit_value_projection(self, node, value):
base = self.visit(node['children'][0], value)
try:
Expand Down

0 comments on commit eec6d99

Please sign in to comment.