Skip to content

Commit

Permalink
Allow empty arrays to be returned (#18)
Browse files Browse the repository at this point in the history
In Jsonata it is a valid response return `[]any{}` from a transform, but
this was previously filtered out.

For example, in jsonata-js, the following input and transform result in
a response of `[]`.
Input:
```
{
  "Account": {
    "Account Name": "Firefly",
    "Order": [
    ]
  }
}
```
Transform: "Account.Order"

The same data and transform resulted in a "no results found" error in
jsonata-go.
  • Loading branch information
Jarrah-libremfg authored May 30, 2023
1 parent d58a160 commit 44fd010
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
3 changes: 0 additions & 3 deletions eval.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,9 +205,6 @@ func evalPath(node *jparse.PathNode, data reflect.Value, env *environment) (refl
return undefined, err
}

if jtypes.IsArray(output) && jtypes.Resolve(output).Len() == 0 {
return undefined, nil
}
}

if node.KeepArrays {
Expand Down
12 changes: 12 additions & 0 deletions jsonata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -621,6 +621,18 @@ func TestArraySelectors4(t *testing.T) {

}

func TestEmptyArray(t *testing.T) {
data := map[string]any{
"thing": []any{},
}
runTestCases(t, data, []*testCase{
{
Expression: "thing",
Output: []any{},
},
})
}

func TestQuotedSelectors(t *testing.T) {

runTestCases(t, testdata.foobar, []*testCase{
Expand Down

0 comments on commit 44fd010

Please sign in to comment.