vitessio/vitess · error · errJSONPath
Invalid JSON path expression.
Error message
Invalid JSON path expression.
What it means
errJSONPath is the sentinel error for invalid JSON path expressions in the eval engine. jsonExtractPath and intoJSONPath return it when the path argument supplied to JSON functions like JSON_EXTRACT cannot be parsed as a valid JSON path.
Source
Thrown at go/vt/vtgate/evalengine/eval_json.go:39
"errors"
"fmt"
"vitess.io/vitess/go/hack"
"vitess.io/vitess/go/mysql/collations/charset"
"vitess.io/vitess/go/mysql/collations/colldata"
"vitess.io/vitess/go/mysql/json"
"vitess.io/vitess/go/sqltypes"
vtrpcpb "vitess.io/vitess/go/vt/proto/vtrpc"
"vitess.io/vitess/go/vt/vterrors"
)
type errJSONType string
func (fn errJSONType) Error() string {
return fmt.Sprintf("Invalid data type for JSON data to function %s; a JSON string or JSON type is required.", string(fn))
}
var errJSONPath = errors.New("Invalid JSON path expression.")
type evalJSON = json.Value
var (
_ eval = (*evalJSON)(nil)
_ hashable = (*evalJSON)(nil)
)
func intoJSON(fn string, e eval) (*evalJSON, error) {
switch e := e.(type) {
case *evalJSON:
return e, nil
case *evalBytes:
var p json.Parser
return p.ParseBytes(e.bytes)
default:
return nil, errJSONType(fn)
}View on GitHub (pinned to 01a25a7d17)
Solutions
- Fix the JSON path syntax (e.g. '$.user.name', '$[0].id') and re-run the query
- Validate the path against MySQL JSON path syntax rules
- Ensure the path argument is a constant string literal or a valid string expression
Example fix
// before SELECT JSON_EXTRACT(doc, 'user[0].name') FROM t; // after SELECT JSON_EXTRACT(doc, '$.user[0].name') FROM t;
Defensive patterns
Strategy: try-catch
Validate before calling
path := "$.user[0].name"
if !strings.HasPrefix(path, "$") {
return errors.New("JSON path must start with '$'")
} Try / catch
val, err := evalJSONExtract(doc, path)
if err != nil && errors.Is(err, errJSONPath) {
// surface path syntax error to caller/query author
} Prevention
- Validate JSON path literals against MySQL JSON path grammar before shipping queries
- Quote and escape paths built dynamically
- Add query tests that exercise each JSON function path
When it happens
Trigger: Calling JSON_EXTRACT/JSON functions with a malformed or non-string path expression, e.g. unbalanced brackets, bad wildcard syntax, or a non-constant/unparseable path value.
Common situations: Typos in JSON path literals in queries; dynamically built paths with incorrect syntax; paths passed as wrong types.
Understand the failure class
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
Related errors
- non-constant regexp
- unreachable
- unreachable
- --batch-size only allowed when all queries are CREATE TABLE|
- query not supported by vexec
AI-assisted analysis of vitessio/vitess@01a25a7d17 (2026-09-01).
Data as JSON: /api/errors/214160bf858ea30a.
Report an issue: GitHub.