MCPcopy
hub / github.com/TomWright/dasel / ExampleSelect

Function ExampleSelect

api_example_test.go:10–37  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

8)
9
10func 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}

Callers

nothing calls this directly

Calls 1

WithUnstableFunction · 0.92

Tested by

no test coverage detected