Compare commits
1 commit
master
...
expr-json-
Author | SHA1 | Date | |
---|---|---|---|
|
493e238455 |
2 changed files with 28 additions and 0 deletions
|
@ -44,6 +44,7 @@ func GetExprEnv(ctx map[string]interface{}) map[string]interface{} {
|
|||
"JsonExtract": JsonExtract,
|
||||
"JsonExtractUnescape": JsonExtractUnescape,
|
||||
"JsonExtractLib": JsonExtractLib,
|
||||
"JsonExtractSlice": JsonExtractSlice,
|
||||
"File": File,
|
||||
"RegexpInFile": RegexpInFile,
|
||||
"Upper": Upper,
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package exprhelpers
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"strings"
|
||||
|
||||
"github.com/buger/jsonparser"
|
||||
|
@ -58,3 +59,29 @@ func JsonExtract(jsblob string, target string) string {
|
|||
log.Tracef("extract path %+v", fullpath)
|
||||
return JsonExtractLib(jsblob, fullpath...)
|
||||
}
|
||||
|
||||
func JsonExtractSlice(jsblob string, target string) []interface{} {
|
||||
if !strings.HasPrefix(target, "[") {
|
||||
target = strings.Replace(target, "[", ".[", -1)
|
||||
}
|
||||
fullpath := strings.Split(target, ".")
|
||||
|
||||
log.Tracef("extract path %+v", fullpath)
|
||||
bContent := JsonExtractLib(jsblob, fullpath...)
|
||||
ret := make([]interface{}, 0)
|
||||
json.Unmarshal([]byte(bContent), &ret)
|
||||
return ret
|
||||
}
|
||||
|
||||
/*func JsonExtractMap(jsblob string, target string) map[string]interface{} {
|
||||
if !strings.HasPrefix(target, "[") {
|
||||
target = strings.Replace(target, "[", ".[", -1)
|
||||
}
|
||||
fullpath := strings.Split(target, ".")
|
||||
|
||||
log.Tracef("extract path %+v", fullpath)
|
||||
bContent := JsonExtractLib(jsblob, fullpath...)
|
||||
ret := make(map[string]interface{}, 0)
|
||||
json.Unmarshal([]byte(bContent), &ret)
|
||||
return ret
|
||||
}*/
|
||||
|
|
Loading…
Reference in a new issue