package main import ( "encoding/json" "fmt" "log" "os/exec" ) func main() { var tree Tree cmd, err := exec.Command("swaymsg", "-t", "get_tree").Output() if err != nil { log.Println(err) } if err := json.Unmarshal(cmd, &tree); err != nil { log.Println(err) } for _, n := range tree.Nodes { if n.Name == "__i3" { for _, nodes := range n.Nodes { if nodes.Name == "__i3_scratch" { fmt.Println(len(nodes.FloatingNodes)) } } } } } // Tree Sway tree type Tree struct { Nodes []struct { ID int64 `json:"id"` Name string `json:"name"` Nodes []struct { ID int `json:"id"` Name string `json:"name"` FloatingNodes []struct { ID int `json:"id"` Name string `json:"name"` } `json:"floating_nodes"` } `json:"nodes"` } `json:"nodes"` }