-
-
Notifications
You must be signed in to change notification settings - Fork 166
Expand file tree
/
Copy pathapi_example_test.go
More file actions
37 lines (32 loc) · 820 Bytes
/
api_example_test.go
File metadata and controls
37 lines (32 loc) · 820 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package dasel_test
import (
"context"
"fmt"
"github.com/tomwright/dasel/v3"
"github.com/tomwright/dasel/v3/execution"
)
func ExampleSelect() {
myData := map[string]any{
"users": []map[string]any{
{"name": "Alice", "age": 30},
{"name": "Bob", "age": 25},
{"name": "Tom", "age": 40},
},
}
query := `users.filter(age > 27).map(name)...`
selectResult, numResults, err := dasel.Select(context.Background(), myData, query, execution.WithUnstable())
if err != nil {
panic(err)
}
fmt.Printf("Found %d results:\n", numResults)
// You should validate the type assertion in real code.
selectResults := selectResult.([]any)
// Results can be of various types, handle accordingly.
for _, result := range selectResults {
fmt.Println(result)
}
// Output:
// Found 2 results:
// Alice
// Tom
}