laravel/framework · error · RuntimeException

This database engine does not support JSON operations.

Error message

This database engine does not support JSON operations.

What it means

Base Grammar::wrapJsonSelector() is overridden by database-specific grammars that support JSON (MySQL, Postgres, SQLite). The base implementation throws RuntimeException to signal that the configured database engine has no JSON path support, so any query using '->' JSON selectors cannot be compiled.

Source

Thrown at src/Illuminate/Database/Grammar.php:177

    {
        if ($value !== '*') {
            return '"'.str_replace('"', '""', $value).'"';
        }

        return $value;
    }

    /**
     * Wrap the given JSON selector.
     *
     * @param  string  $value
     * @return string
     *
     * @throws \RuntimeException
     */
    protected function wrapJsonSelector($value)
    {
        throw new RuntimeException('This database engine does not support JSON operations.');
    }

    /**
     * Determine if the given string is a JSON selector.
     *
     * @param  string  $value
     * @return bool
     */
    protected function isJsonSelector($value)
    {
        return str_contains($value, '->');
    }

    /**
     * Convert an array of column names into a delimited string.
     *
     * @param  array<\Illuminate\Contracts\Database\Query\Expression|string>  $columns
     * @return string

View on GitHub (pinned to bd6b5437e6)

Solutions

  1. Switch to a database engine with JSON support (MySQL 5.7+, Postgres, SQLite) for connections using JSON columns.
  2. Avoid JSON selectors on the unsupported engine; store the data in dedicated columns or a text column with manual (de)serialization.
  3. Provide a custom Grammar for the engine that implements wrapJsonSelector() if you must use JSON paths.
  4. Verify the connection's grammar actually supports JSON before issuing JSON queries (e.g. feature-detect or guard by driver name).

Example fix

// before
// config: 'default' => env('DB_CONNECTION', 'sqlsrv')
Item::whereJsonContains('meta->tags', 'sale')->get(); // throws on sqlsrv

// after
// switch connection to mysql in .env: DB_CONNECTION=mysql
// or store meta as columns and query directly:
Item::where('tag', 'sale')->get();
Defensive patterns

Strategy: validation

Validate before calling

$grammar = \DB::connection()->getQueryGrammar();
if (! (new \ReflectionMethod($grammar, 'wrapJsonSelector'))->getDeclaringClass()->getName() !== \Illuminate\Database\Grammar::class) {
    throw new \RuntimeException('Driver '.get_class($grammar).' lacks JSON support.');
}

Type guard

function driverSupportsJson(): bool {
    $grammar = \DB::connection()->getQueryGrammar();
    return (new \ReflectionMethod($grammar, 'wrapJsonSelector'))
        ->getDeclaringClass()->getName() !== \Illuminate\Database\Grammar::class;
}

Try / catch

try {
    Model::whereJsonContains('meta->tags', 'x')->get();
} catch (\RuntimeException $e) {
    if (str_contains($e->getMessage(), 'does not support JSON operations')) {
        // fall back to scalar columns or different driver
    }
    throw $e;
}

Prevention

When it happens

Trigger: Using JSON column access (e.g. whereJsonContains, -> operators, JSON casts) on a connection whose grammar does not override wrapJsonSelector (e.g. older SQL Server / sqlsrv, or a custom/unmapped driver).

Common situations: Running migrations or queries with JSON columns on SQL Server; switching a project from MySQL to a driver lacking JSON support; packages that assume JSON support; environment differences between dev (MySQL) and CI/other DBs.

Related errors


AI-assisted analysis of laravel/framework@bd6b5437e6 (2026-08-06). Data as JSON: /data/errors/9712b4b9d0dc3394.json. Report an issue: GitHub.