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

  1. Fix the JSON path syntax (e.g. '$.user.name', '$[0].id') and re-run the query
  2. Validate the path against MySQL JSON path syntax rules
  3. 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

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

Related errors


AI-assisted analysis of vitessio/vitess@01a25a7d17 (2026-09-01). Data as JSON: /api/errors/214160bf858ea30a. Report an issue: GitHub.