Use as a go package
Import
go get github.com/tomwright/daselUsage
package main
import (
"encoding/json"
"fmt"
"github.com/tomwright/dasel"
)
func main() {
var data interface{}
_ = json.Unmarshal([]byte(`[{"name": "Tom"}, {"name": "Jim"}]`), &data)
rootNode := dasel.New(data)
result, _ := rootNode.Query(".[0].name")
printNodeValue(result) // Tom
results, _ := rootNode.QueryMultiple(".[*].name")
printNodeValue(results...) // Tom\nJim
_ = rootNode.Put(".[0].name", "Frank")
printNodeValue(rootNode) // [map[name:Frank] map[name:Jim]]
_ = rootNode.PutMultiple(".[*].name", "Joe")
printNodeValue(rootNode) // [map[name:Joe] map[name:Joe]]
outputBytes, _ := json.Marshal(rootNode.InterfaceValue())
fmt.Println(string(outputBytes)) // [{"name":"Joe"},{"name":"Joe"}]
}
func printNodeValue(nodes ...*dasel.Node) {
for _, n := range nodes {
fmt.Println(n.InterfaceValue())
}
}Last updated