{"record":{"id":"9712b4b9d0dc3394","repo":"laravel/framework","slug":"this-database-engine-does-not-support-json-operati","errorCode":null,"errorMessage":"This database engine does not support JSON operations.","messagePattern":"This database engine does not support JSON operations\\.","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"src/Illuminate/Database/Grammar.php","lineNumber":177,"sourceCode":"    {\n        if ($value !== '*') {\n            return '\"'.str_replace('\"', '\"\"', $value).'\"';\n        }\n\n        return $value;\n    }\n\n    /**\n     * Wrap the given JSON selector.\n     *\n     * @param  string  $value\n     * @return string\n     *\n     * @throws \\RuntimeException\n     */\n    protected function wrapJsonSelector($value)\n    {\n        throw new RuntimeException('This database engine does not support JSON operations.');\n    }\n\n    /**\n     * Determine if the given string is a JSON selector.\n     *\n     * @param  string  $value\n     * @return bool\n     */\n    protected function isJsonSelector($value)\n    {\n        return str_contains($value, '->');\n    }\n\n    /**\n     * Convert an array of column names into a delimited string.\n     *\n     * @param  array<\\Illuminate\\Contracts\\Database\\Query\\Expression|string>  $columns\n     * @return string","sourceCodeStart":159,"sourceCodeEnd":195,"githubUrl":"https://github.com/laravel/framework/blob/e0f6eb3518ac29fbbca8529e97d0df7fc9f24481/src/Illuminate/Database/Grammar.php#L159-L195","documentation":"The base Grammar class's wrapJsonSelector() throws because the database engine in use does not override it to support JSON path selectors. Whenever the query builder encounters a column containing '->' (a JSON path), it calls wrapJsonSelector; on a driver without JSON support (the base Grammar, or one that did not override) it refuses rather than emit broken SQL.","triggerScenarios":"Using a '->' JSON selector (e.g. where('meta->theme', 'dark') or ->select('users->name')) against a connection whose schema grammar extends the base Grammar (no JSON support). Common with the base/abstract grammar, some sqlsrv configurations, or a misconfigured custom connection.","commonSituations":"Developing with JSON columns on MySQL/PostgreSQL then running tests on a driver that lacks override; a custom DB driver/connection that forgot to override wrapJsonSelector; SQLite < 3.9 / older setups; using -> on a connection that resolves to the base Grammar.","solutions":["Switch the connection to a driver that supports JSON (mysql with json_get, pgsql with ->/->>).","Avoid '->' selectors for this connection - cast/store the field as a regular column or use a manual whereRaw with the engine's JSON function.","If you wrote a custom Grammar, override wrapJsonSelector (and wrapJsonFieldAndPath) to emit correct SQL.","Check config/database.php that the connection maps to the intended driver."],"exampleFix":"// before - throws on a driver without JSON support\n$users = User::where('preferences->theme', 'dark')->get();\n\n// after - use the engine's native function via whereRaw (sqlsrv example)\n$users = User::whereRaw(\"JSON_VALUE(preferences, '$.theme') = ?\", ['dark'])->get();\n// or migrate the column to a real table column / use a supported driver","handlingStrategy":"validation","validationCode":"// Detect JSON-selector usage on a driver that does not override wrapJsonSelector\n$grammar = \\DB::connection()->getQueryGrammar();\nif (str_contains($column, '->') && (new \\ReflectionMethod($grammar, 'wrapJsonSelector'))->getDeclaringClass()->getName() === \\Illuminate\\Database\\Grammar::class) {\n    throw new \\RuntimeException('Current DB driver does not support JSON selectors; use whereRaw().');\n}","typeGuard":"function driverSupportsJson(\\Illuminate\\Database\\Connection $connection): bool {\n    $r = new \\ReflectionMethod($connection->getQueryGrammar(), 'wrapJsonSelector');\n    return $r->getDeclaringClass()->getName() !== \\Illuminate\\Database\\Grammar::class;\n}","tryCatchPattern":"try {\n    $users = User::where('meta->theme', 'dark')->get();\n} catch (\\RuntimeException $e) {\n    if (str_contains($e->getMessage(), 'does not support JSON operations')) {\n        // rewrite using the engine's native function\n        $users = User::whereRaw(\"JSON_VALUE(meta, '$.theme') = ?\", ['dark'])->get();\n    } else { throw $e; }\n}","preventionTips":["Confirm config/database.php maps the connection to a JSON-capable driver (mysql/pgsql).","Avoid '->' selectors for connections that may resolve to the base Grammar.","If you wrote a custom Grammar, override wrapJsonSelector and wrapJsonFieldAndPath.","Use whereRaw with the engine's JSON function as a portable fallback."],"tags":["database","grammar","json","query-builder","driver"],"backgroundTag":null,"analyzedSha":"e0f6eb3518ac29fbbca8529e97d0df7fc9f24481","analyzedAt":"2026-08-11T20:52:37.562Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}