Skip to content

Commit 4c3b12e

Browse files
committed
fix wildcard handling
1 parent 7a99631 commit 4c3b12e

3 files changed

Lines changed: 16 additions & 8 deletions

File tree

src/jsonata/jsonata.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -684,9 +684,6 @@ def evaluate_wildcard(self, expr: Optional[parser.Parser.Symbol], input: Optiona
684684
if isinstance(value, list):
685685
value = self.flatten(value, None)
686686
results = functions.Functions.append(results, value)
687-
elif isinstance(value, dict):
688-
# Call recursively do decompose the map
689-
results.extend(self.evaluate_wildcard(expr, value))
690687
else:
691688
results.append(value)
692689

src/jsonata/utils.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,7 @@ def is_function(o: Optional[Any]) -> bool:
7474
@staticmethod
7575
def create_sequence(el: Optional[Any] = NONE) -> list:
7676
if el is not Utils.NONE:
77-
if isinstance(el, list) and len(el) == 1:
78-
sequence = Utils.JList(el)
79-
else:
80-
# This case does NOT exist in Javascript! Why?
81-
sequence = Utils.JList([el])
77+
sequence = Utils.JList([el])
8278
else:
8379
sequence = Utils.JList()
8480
sequence.sequence = True

tests/array_test.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,18 @@ class TestArray:
55

66
def test_array(self):
77
assert jsonata.Jsonata("$.[{ }] ~> $reduce($append)").evaluate([True, True]) == [{}, {}]
8+
9+
def test_wildcard(self):
10+
expr = jsonata.Jsonata("*")
11+
assert expr.evaluate([{"x": 1}]) == {"x": 1}
12+
13+
def test_wildcard_filter(self):
14+
value1 = {"value": {"Name": "Cell1", "Product": "Product1"}}
15+
value2 = {"value": {"Name": "Cell2", "Product": "Product2"}}
16+
data = [value1, value2]
17+
18+
expression = jsonata.Jsonata("*[value.Product = 'Product1']")
19+
assert expression.evaluate(data) == value1
20+
21+
expression2 = jsonata.Jsonata("**[value.Product = 'Product1']")
22+
assert expression2.evaluate(data) == value1

0 commit comments

Comments
 (0)