Open ssikdar1 opened 5 years ago
Currently in dap:
dap
$ echo '{"id": 1, "info.name":"jon snow", "info.dead": false, "info.age": 29}' | dap json + expand info + json {"id":1,"info.name":"jon snow","info.dead":false,"info.age":29,"info":{"name":"jon snow","dead":false,"age":29}}
However trying go dap:
$ echo '{"id": 1, "info.name":"jon snow", "info.dead": false, "info.age": 29}' | ./dappy json + expand info + json Error: Invalid filter plugin: expand
We probably could use some variation of this script (inspiration taken from the dap) in ./filter/simple.go:
./filter/simple.go
package main import ( "fmt" "os" "io/ioutil" "regexp" "encoding/json" ) func main() { bytes, _ := ioutil.ReadAll(os.Stdin) myMap := make(map[string]interface{}) _ = json.Unmarshal([]byte(bytes), &myMap) pattern := fmt.Sprintf("^%s\\.(?P<sub_key>.+)$", os.Args[1]) r := regexp.MustCompile(pattern) tmp := make(map[string]interface{}) for k, v := range myMap { match := r.FindStringSubmatch(k) if(len(match) > 0){ tmp[match[1]] = v } } myMap[os.Args[1]] = tmp jsonString, _ := json.Marshal(myMap) fmt.Println(string(jsonString)) }
sample run:
Currently in
dap
:However trying go dap:
We probably could use some variation of this script (inspiration taken from the dap) in
./filter/simple.go
:sample run: