0 follower

Final Class Yiisoft\Db\Expression\Value\JsonValue

InheritanceYiisoft\Db\Expression\Value\JsonValue
ImplementsYiisoft\Db\Expression\ExpressionInterface

Represents data to encode to JSON.

For example:

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

Public Methods

Hide inherited methods

Method Description Defined By
__construct() Yiisoft\Db\Expression\Value\JsonValue

Property Details

Hide inherited properties

$type public property
public string|null $type null
$value public property
public mixed $value null

Method Details

Hide inherited methods

__construct() public method

public mixed __construct ( mixed $value, string|null $type null )
$value mixed

The JSON content. It can be represented as

  • an array of values;
  • an instance which implements {@see \Yiisoft\Db\Expression\Value\Traversable} or {@see \Yiisoft\Db\Expression\Value\JsonSerializable} and represents an array of values;
  • an instance of {@see \Yiisoft\Db\Expression\Value\QueryInterface} that represents an SQL sub-query;
  • a valid JSON encoded array as a string, e.g. '[1,2,3]' or '{"a":1,"b":2}';
  • any other value compatible with {@see \json_encode()} input requirements.
$type string|null

Type of database column, value should be cast to. Defaults to null, meaning no explicit casting will be performed. This property is used only for DBMSs that support different types of JSON. For example, PostgresSQL has json and jsonb types.

                public function __construct(public readonly mixed $value, public readonly ?string $type = null) {}