{"record":{"id":"9cf892bf1412d0f3","repo":"yiisoft/yii2","slug":"the-jsonexpression-class-can-not-be-serialized-to","errorCode":null,"errorMessage":"The JsonExpression class can not be serialized to JSON when the value is a QueryInterface object","messagePattern":"The JsonExpression class can not be serialized to JSON when the value is a QueryInterface object","errorType":"exception","errorClass":"yii\\base\\InvalidConfigException","httpStatus":null,"severity":"error","filePath":"framework/db/JsonExpression.php","lineNumber":94,"sourceCode":"    {\n        return $this->type;\n    }\n\n    /**\n     * Specify data which should be serialized to JSON\n     *\n     * @link https://www.php.net/manual/en/jsonserializable.jsonserialize.php\n     * @return mixed data which can be serialized by <b>json_encode</b>,\n     * which is a value of any type other than a resource.\n     * @since 2.0.14.2\n     * @throws InvalidConfigException when JsonExpression contains QueryInterface object\n     */\n    #[\\ReturnTypeWillChange]\n    public function jsonSerialize()\n    {\n        $value = $this->getValue();\n        if ($value instanceof QueryInterface) {\n            throw new InvalidConfigException('The JsonExpression class can not be serialized to JSON when the value is a QueryInterface object');\n        }\n\n        return $value;\n    }\n}\n","sourceCodeStart":76,"sourceCodeEnd":100,"githubUrl":"https://github.com/yiisoft/yii2/blob/66f00d18a29b520f85e8e8f1e32d1e7e7b556cac/framework/db/JsonExpression.php#L76-L100","documentation":"Error \"The JsonExpression class can not be serialized to JSON when the value is a QueryInterface object\" thrown in yiisoft/yii2.","triggerScenarios":"Thrown at framework/db/JsonExpression.php:94 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"66f00d18a29b520f85e8e8f1e32d1e7e7b556cac","analyzedAt":"2026-08-17T05:17:23.470Z","schemaVersion":2},"datasetVersion":"2026-08-17T09:17:11.063Z"}