Debian Codegraph @

api_example_test.go

raw symbols SCIP
1 package dasel_test
2
3 import (
4 "context"
5 "fmt"
6 "github.com/tomwright/dasel/v3"
7 "github.com/tomwright/dasel/v3/execution"
8 )
9
10 func ExampleSelect() {
11 myData := map[string]any{
12 "users": []map[string]any{
13 {"name": "Alice", "age": 30},
14 {"name": "Bob", "age": 25},
15 {"name": "Tom", "age": 40},
16 },
17 }
18 query := `users.filter(age > 27).map(name)...`
19 selectResult, numResults, err := dasel.Select(context.Background(), myData, query, execution.WithUnstable())
20 if err != nil {
21 panic(err)
22 }
23 fmt.Printf("Found %d results:\n", numResults)
24
25 // You should validate the type assertion in real code.
26 selectResults := selectResult.([]any)
27
28 // Results can be of various types, handle accordingly.
29 for _, result := range selectResults {
30 fmt.Println(result)
31 }
32
33 // Output:
34 // Found 2 results:
35 // Alice
36 // Tom
37 }