| 1 | package dasel_testscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3_test`/ |
| 2 | |
| 3 | import ( |
| 4 | "contextscip-go gomod github.com/golang/go/src go1.25 context/" |
| 5 | "fmtscip-go gomod github.com/golang/go/src go1.25 fmt/" |
| 6 | "github.com/tomwright/dasel/v3scip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3`/" |
| 7 | "github.com/tomwright/dasel/v3/executionscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/execution`/" |
| 8 | ) |
| 9 | |
| 10 | func ExampleSelectscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3_test`/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 := daselscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3`/.Selectscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3`/Select().(contextscip-go gomod github.com/golang/go/src go1.25 context/.Backgroundscip-go gomod github.com/golang/go/src go1.25 context/Background().(), myData, query, executionscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/execution`/.WithUnstablescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/execution`/WithUnstable().()) |
| 20 | if err != nil { |
| 21 | panic(err) |
| 22 | } |
| 23 | fmtscip-go gomod github.com/golang/go/src go1.25 fmt/.Printfscip-go gomod github.com/golang/go/src go1.25 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 | fmtscip-go gomod github.com/golang/go/src go1.25 fmt/.Printlnscip-go gomod github.com/golang/go/src go1.25 fmt/Println().(result) |
| 31 | } |
| 32 | |
| 33 | // Output: |
| 34 | // Found 2 results: |
| 35 | // Alice |
| 36 | // Tom |
| 37 | } |