fix: extract data using jmespath

Change-Id: Icea3b8fa7e71dd610c19c91e21a259104ab2fe30
This commit is contained in:
buyuxiang
2022-02-20 13:43:28 +08:00
parent 6bb96e8eac
commit 54402ad5f7
5 changed files with 63 additions and 4 deletions

View File

@@ -69,8 +69,7 @@ func (p *parser) parseData(raw interface{}, variablesMapping map[string]interfac
case reflect.String:
// json.Number
if rawValue, ok := raw.(json.Number); ok {
// use the same rule as json.Unmarshal (float64, for JSON numbers)
return rawValue.Float64()
return parseJSONNumber(rawValue)
}
// other string
value := rawValue.String()
@@ -109,6 +108,16 @@ func (p *parser) parseData(raw interface{}, variablesMapping map[string]interfac
}
}
func parseJSONNumber(raw json.Number) (interface{}, error) {
if strings.Contains(raw.String(), ".") {
// float64
return raw.Float64()
} else {
// int64
return raw.Int64()
}
}
const (
regexVariable = `[a-zA-Z_]\w*` // variable name should start with a letter or underscore
regexFunctionName = `[a-zA-Z_]\w*` // function name should start with a letter or underscore