Check if the key is a known json attribute and return that value.

@param string $key
@param mixed  $value

@return mixed

@throws InvalidJsonException
324259
protected function mutateAttribute($key, $value)
    {
        $jsonPattern = '/'.implode('|', self::$jsonOperators).'/';

        // Test for JSON operators and reduce to end element
        $containsJsonOperator = false;

        if (preg_match($jsonPattern, $key)) {
            $elems = preg_split($jsonPattern, $key);
            $key = end($elems);
            $key = str_replace(['>', "'"], '', $key);

            $containsJsonOperator = true;
        }

        if (!parent::hasGetMutator($key) && array_key_exists($key, $this->jsonAttributes) != false) {

            // Get the content of the column associated with this JSON
            // attribute and parse it into an object
            $value = $this->{$this->jsonAttributes[$key]};
            $obj = json_decode($this->{$this->jsonAttributes[$key]});

            // Make sure we were able to parse the json. It's possible here
            // that we've only hinted at an attribute and the column that will
            // hold that attribute is actually null. This isn't really a parse
            // error though the json_encode method will return null (just like)
            // a parse error. To distinguish the two states see if the original
            // value was null (indicating there was nothing there to parse in
            // the first place)
            if ( !($value === 'null' || $value === null) && $obj === null ) {
                throw new InvalidJsonException();
            }

            // Again it's possible the key will be in the jsonAttributes array
            // (having been hinted) but not present on the actual record.
            // Therefore test that the key is set before returning.
            if (isset($obj->$key)) {
                return $obj->$key;
            } else {
                return;
            }
        } elseif ($containsJsonOperator) {
            return;
        }

        return parent::mutateAttribute($key, $value);
    }
534337
protected function checkValue($value, $key = null)
    {
        if ($value != null) {
            if ($key !== null) {
                return isset($value[$key]) ? $value[$key] : null;
            }

            return $value;
        }
    }
951022
public function setJsonValue(array $value)
    {
        $value = array_map(
            function ($value) {
                return str_replace(':', '', $value);
            },
            $value
        );
        parent::setJsonValue($value);
    }
47520
protected function jsonDecode($value, $errorMessage = null) {
        $decoded = json_decode($value, true);

        if (json_last_error() !== JSON_ERROR_NONE) {
            throw new InvalidArgumentException(
                $errorMessage ?: 'The supplied parameter is not a valid JSON object.'
            );
        }

        return $decoded;
    }
464305
public static function encode($value)
    {
        $encoded = json_encode($value, JSON_UNESCAPED_UNICODE);

        if (JSON_ERROR_NONE !== json_last_error()) {
            throw new \InvalidArgumentException(sprintf(
                'Could not encode value into json. Error %s and message %s',
                json_last_error(),
                json_last_error_msg()
            ));
        }

        return $encoded;
    }
1196652
protected function castAttribute($key, $value)
    {
        if (is_null($value)) {
            return $value;
        }

        switch ($this->getCastType($key)) {
            case 'int':
            case 'integer':
                return (int) $value;
            case 'real':
            case 'float':
            case 'double':
                return $this->fromFloat($value);
            case 'decimal':
                return $this->asDecimal($value, explode(':', $this->getCasts()[$key], 2)[1]);
            case 'string':
                return (string) $value;
            case 'bool':
            case 'boolean':
                return (bool) $value;
            case 'object':
                return $this->fromJson($value, true);
            case 'array':
            case 'json':
                return $this->fromJson($value);
            case 'collection':
                return new BaseCollection($this->fromJson($value));
            case 'date':
                return $this->asDate($value);
            case 'datetime':
            case 'custom_datetime':
                return $this->asDateTime($value);
            case 'timestamp':
                return $this->asTimestamp($value);
            default:
                return $value;
        }
    }
199371
public function parseValue($key, $value)
    {
        $attrs = $this->getAttrs();

        if (!isset($attrs[$key]) && is_object($value)) {
            // Handle dates
            if (!$value instanceof \MongoDate
                && !$value instanceof \MongoId
                && !$value instanceof \MongoDBRef) {

                if ($value instanceof \DateTime) {
                    $value = new \MongoDate($value->getTimestamp());
                } else if (method_exists($value, 'toArray')) {
                    $value = (array) $value->toArray();
                } elseif (method_exists($value, 'to_array')) {
                    $value = (array) $value->to_array();
                }else{
                    //ingore this object when saving
                    $this->ignoreData[$key] = $value;
                }
            }
        } elseif (isset($attrs[$key]) && isset($attrs[$key]['type'])) {


            switch ($attrs[$key]['type']) {
                case self::DATA_TYPE_INT:
                case self::DATA_TYPE_INTEGER:
                    $value = (integer) $value;
                    break;
                case self::DATA_TYPE_STR:
                case self::DATA_TYPE_STRING:
                    $value = (string) $value;
                    break;
                case self::DATA_TYPE_FLT:
                case self::DATA_TYPE_FLOAT:
                case self::DATA_TYPE_DBL;
                case self::DATA_TYPE_DOUBLE:
                    $value = (float) $value;
                    break;
                case self::DATA_TYPE_TIMESTAMP:
                    if (! ($value instanceof \MongoTimestamp)) {
                        try {
                            $value = new \MongoTimestamp($value);
                        } catch (\Exception $e) {
                            echo 'bbb';exit();
                            throw new InvalidDataTypeException('$key cannot be parsed by \MongoTimestamp', $e->getCode(), $e);
                        }
                    }
                    break;
                case self::DATA_TYPE_DATE:
                    if (! ($value instanceof \MongoDate)) {
                        try {
                            if (!$value instanceof \MongoDate) {
                                if (is_numeric($value)) {
                                    $value = '@'.$value;
                                }
                                if (!$value instanceof \DateTime) {
                                    $value = new \DateTime($value);
                                }
                                $value = new \MongoDate($value->getTimestamp());
                            }
                        } catch (\Exception $e) {
                            throw new InvalidDataTypeException('$key cannot be parsed by \DateTime', $e->getCode(), $e);
                        }
                    }
                    break;
                case self::DATA_TYPE_BOOL:
                case self::DATA_TYPE_BOOLEAN:
                    $value = (boolean) $value;
                    break;
                case self::DATA_TYPE_OBJ:
                case self::DATA_TYPE_OBJECT:
                    if (!empty($value) && !is_array($value) && !is_object($value)) {
                        throw new InvalidDataTypeException("[$key] is not an object");
                    }
                    $value = (object) $value;
                    break;
                case self::DATA_TYPE_ARRAY:
                    if (!empty($value) && !is_array($value)) {
                        throw new InvalidDataTypeException("[$key] is not an array");
                    }
                    $value = (array) $value;
                    break;
                case self::DATA_TYPE_EMBED:
                case self::DATA_TYPE_EMBEDS:
                case self::DATA_TYPE_MIXED:
                case self::DATA_TYPE_REFERENCE:
                case self::DATA_TYPE_REFERENCES:
                    break;
                default:
                    throw new InvalidDataTypeException("{$attrs[$key]['type']} is not a valid type");
                    break;
            }
        }

        return $value;
    }
691505
protected function getJsonBindingParameter($value)
    {
        if ($value instanceof Expression) {
            return $value->getValue();
        }

        switch ($type = gettype($value)) {
            case 'boolean':
                return $value ? 'true' : 'false';
            case 'NULL':
            case 'integer':
            case 'double':
            case 'string':
                return '?';
            case 'object':
            case 'array':
                return '?';
        }

        throw new InvalidArgumentException("JSON value is of illegal type: {$type}");
    }
725104
public function getValue()
    {
        $value = json_decode($this->value, true);
        if (json_last_error() !== JSON_ERROR_NONE) {
            throw new InvalidJsonException("Invalid JSON config value for id: " . $this->getId());
        }

        return $value;
    }
1316675
public function getValue($key) {
		if(isset($this->jsonArray[$key])) {
			return $this->jsonArray[$key];
		}

		return NULL;
	}
347890
private function getValue($value)
    {
        switch ($this->attributes['type']) {
            case 'int':
            case 'integer':
                return (int) $value;
            case 'real':
            case 'float':
            case 'double':
                return (float) $value;
            case 'bool':
            case 'boolean':
                return (bool) $value;
            case 'collection':
                return new Collection(json_decode($value, true));
            case 'object':
                return json_decode($value);
            case 'array':
                return json_decode($value, true);
            default:
                return $value;
        }
    }
888638
public function setAttribute($key, $value) {
    if (($key == static::$table_type_field) || (!$this->isInAllAttributes($key))) {
      throw new InvalidAttributeException("The attribute {$key} is non available.");
    }

    return parent::setAttribute($key, $value);
  }
696020
public function setJson($key, $value = null): void
    {
        if (is_array($key)) {
            foreach ($key as $k => $v) {
                $this->setJson($k, $v);
            }
            return;
        }

        $this->_jsonData[$key] = $value;
    }
789704
public function setAttribute($key, $value)
    {
        // First we will check for the presence of a mutator for the set operation
        // which simply lets the developers tweak the attribute as it is set on
        // the model, such as "json_encoding" an listing of data for storage.
        if ($this->hasSetMutator($key)) {
            $method = 'set'.str_studly($key).'Attribute';

            return $this->{$method}($value);
        }
        // If an attribute is listed as a "date", we'll convert it from a DateTime
        // instance into a form proper for storage on the database tables using
        // the connection grammar's date format. We will auto set the values.
        elseif ($value && (in_array($key, $this->getDates()) || $this->isDateCastable($key))) {
            $value = $this->fromDateTime($value);
        }

        if ($this->isJsonCastable($key) && ! is_null($value)) {
            $value = $this->castAttributeAsJson($value);
        }

        // If this attribute contains a JSON ->, we'll set the proper value in the
        // attribute's underlying array. This takes care of properly nesting an
        // attribute in the array's value in the case of deeply nested items.
        if (mb_strpos($key, '->') !== false) {
            return $this->fillJsonAttribute($key, $value);
        }

        $this->attributes[$key] = $value;

        return $this;
    }
484806
protected function resolveValue($value)
    {
        do {
            if ($value instanceof \JsonSerializable) {
                $value = $value->jsonSerialize();
            } elseif ($value instanceof \Closure) {
                $value = $value();
            } else {
                break;
            }
        } while (true);

        return $value;
    }
501391
public function isJson($value)
    {
        if (!is_scalar($value) && !method_exists($value, '__toString')) {
            return false;
        }

        json_decode($value);

        return json_last_error() === JSON_ERROR_NONE;
    }
546703
protected function castAttribute($key, $value)
    {
        if (is_null($value)) {
            return $value;
        }

        switch ($this->getCastType($key)) {
            case 'int':
            case 'integer':
                return (int)$value;
            case 'real':
            case 'float':
            case 'double':
                return (float)$value;
            case 'string':
                return (string)$value;
            case 'bool':
            case 'boolean':
                return filter_var($value, FILTER_VALIDATE_BOOLEAN);
            case 'object':
                return is_array($value)
                    ? json_decode(json_encode($value))
                    : json_decode($value);
            case 'array':
            case 'json':
                return json_decode($value, true);
            case 'date':
            case 'datetime':
                return $this->asDateTime($value);
            case 'timestamp':
                return $this->asTimeStamp($value);
            default:
                return $value;
        }
    }