Skip to content

Commit

Permalink
Merge pull request #11 from rayokota/correct-array
Browse files Browse the repository at this point in the history
Correct behavior of $append function
  • Loading branch information
rayokota authored Nov 13, 2024
2 parents 93345fd + 3a91db4 commit fe376d1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
8 changes: 1 addition & 7 deletions src/jsonata/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2010,15 +2010,9 @@ def append(arg1: Optional[Any], arg2: Optional[Any]) -> Optional[Any]:
arg1 = utils.Utils.create_sequence(arg1)
if not (isinstance(arg2, list)):
arg2 = utils.Utils.JList([arg2])
# else
# // Arg2 was a list: add it as a list element (don't flatten)
# ((List)arg1).add((List)arg2)

arg1 = utils.Utils.JList(arg1) # create a new copy!
if isinstance(arg2, utils.Utils.JList) and arg2.cons:
arg1.append(arg2)
else:
arg1.extend(arg2)
arg1.extend(arg2)
return arg1

@staticmethod
Expand Down
7 changes: 7 additions & 0 deletions tests/array_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import jsonata


class TestArray:

def test_array(self):
assert jsonata.Jsonata("$.[{ }] ~> $reduce($append)").evaluate([True, True]) == [{}, {}]

0 comments on commit fe376d1

Please sign in to comment.