yiisoft/yii2 · error · yii\base\InvalidConfigException

The JsonExpression class can not be serialized to JSON when

Error message

The JsonExpression class can not be serialized to JSON when the value is a QueryInterface object

What it means

Error "The JsonExpression class can not be serialized to JSON when the value is a QueryInterface object" thrown in yiisoft/yii2.

Source

Thrown at framework/db/JsonExpression.php:94

    {
        return $this->type;
    }

    /**
     * Specify data which should be serialized to JSON
     *
     * @link https://www.php.net/manual/en/jsonserializable.jsonserialize.php
     * @return mixed data which can be serialized by <b>json_encode</b>,
     * which is a value of any type other than a resource.
     * @since 2.0.14.2
     * @throws InvalidConfigException when JsonExpression contains QueryInterface object
     */
    #[\ReturnTypeWillChange]
    public function jsonSerialize()
    {
        $value = $this->getValue();
        if ($value instanceof QueryInterface) {
            throw new InvalidConfigException('The JsonExpression class can not be serialized to JSON when the value is a QueryInterface object');
        }

        return $value;
    }
}

View on GitHub (pinned to 66f00d18a2)

When it happens

Trigger: Thrown at framework/db/JsonExpression.php:94 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of yiisoft/yii2@66f00d18a2 (2026-08-17). Data as JSON: /api/errors/9cf892bf1412d0f3. Report an issue: GitHub.