Class yii\db\JsonExpression

Inheritanceyii\db\JsonExpression
ImplementsJsonSerializable, yii\db\ExpressionInterface
Available since version2.0.14
Source Code https://github.com/yiisoft/yii2/blob/master/framework/db/JsonExpression.php

Class JsonExpression represents data that should be encoded to JSON.

For example:

new JsonExpression(['a' => 1, 'b' => 2]); // will be encoded to '{"a": 1, "b": 2}'

Protected Properties

Hide inherited properties

PropertyTypeDescriptionDefined By
$type string|null Type of JSON, expression should be casted to. yii\db\JsonExpression
$value mixed The value to be encoded to JSON. yii\db\JsonExpression

Constants

Hide inherited constants

ConstantValueDescriptionDefined By
TYPE_JSON 'json' yii\db\JsonExpression
TYPE_JSONB 'jsonb' yii\db\JsonExpression

Property Details

$type protected property

Type of JSON, expression should be casted to. Defaults to null, meaning no explicit casting will be performed. This property will be encountered only for DBMSs that support different types of JSON. For example, PostgreSQL has json and jsonb types.

protected string|null $type null
$value protected property

The value to be encoded to JSON. The value must be compatible with [\yii\helpers\Json::encode()|Json::encode()]] input requirements.

protected mixed $value null

Method Details

__construct() public method

JsonExpression constructor.

See also $type.

public void __construct ( $value, $type null )
$value mixed

The value to be encoded to JSON. The value must be compatible with [\yii\helpers\Json::encode()|Json::encode()]] requirements.

$type string|null

The type of the JSON. See yii\db\JsonExpression::$type

getType() public method

See also $type.

public string|null getType ( )
return string|null

The type of JSON

getValue() public method

See also $value.

public mixed getValue ( )
jsonSerialize() public method

public void jsonSerialize ( )