githubEdit

Using dasel as a go package

Getting a root node

You can convert values into something usable by dasel with dasel.ValueOfarrow-up-right.

myValue := map[string]any{
    "name": "Tom"
}
rootNode := dasel.ValueOf(myValue)

It's worth mentioning that this step isn't required because the commands listed below will do this conversion internally.

Running commands

func main() {
	myValue := map[string]any{
		"firstName": "Tom",
		"lastName":  "Wright",
	}
	values, err := dasel.Select(myValue, "firstName")
	if err != nil {
		log.Fatalf("could not select: %s", err)
	}

	results := values.Interfaces()
	stringResults := make([]string, len(results))
	for k, v := range results {
		stringResults[k] = fmt.Sprint(v)
	}
	fmt.Printf("select result: %s", strings.Join(stringResults, ", "))
	// select result: Tom
}

Note that if you pass a pointer, the original value also gets updated.

Note that if you pass a pointer, the original value also gets updated.

Last updated