From eec6d99c99e6f1f8c6447b0939d8b26c3eba2566 Mon Sep 17 00:00:00 2001 From: Springcomp Date: Wed, 15 Jan 2025 20:49:38 +0100 Subject: [PATCH] [ternary] supports ternary operator expressions --- jmespath/visitor.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/jmespath/visitor.py b/jmespath/visitor.py index 9224f52..b39f38c 100644 --- a/jmespath/visitor.py +++ b/jmespath/visitor.py @@ -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: