private function castAsJson($value, bool $asArray = false)
	{
		$tmp = ! is_null($value) ? ($asArray ? [] : new \stdClass) : null;
		if (function_exists('json_decode'))
		{
			if ((is_string($value) && (strpos($value, '[') === 0 || strpos($value, '{') === 0 || (strpos($value, '"') === 0 && strrpos($value, '"') === 0 ))) || is_numeric($value))
			{
				$tmp = json_decode($value, $asArray);

				if (json_last_error() !== JSON_ERROR_NONE)
				{
					throw CastException::forInvalidJsonFormatException(json_last_error());
				}
			}
		}
		return $tmp;
	}
private function castAsJson($value, bool $asArray = false)
	{
		$tmp = ! is_null($value) ? ($asArray ? [] : new \stdClass) : null;
		if (function_exists('json_decode'))
		{
			if ((is_string($value) && (strpos($value, '[') === 0 || strpos($value, '{') === 0 || (strpos($value, '"') === 0 && strrpos($value, '"') === 0 ))) || is_numeric($value))
			{
				$tmp = json_decode($value, $asArray);

				if (json_last_error() !== JSON_ERROR_NONE)
				{
					throw CastException::forInvalidJsonFormatException(json_last_error());
				}
			}
		}
		return $tmp;
	}
private function castAsJson ( $ value , bool $ asArray = false ) { $ tmp = ! is_null ( $ value ) ? ( $ asArray ? [ ] : new \ stdClass ) : null ; if ( function_exists ( 'json_decode' ) ) { if ( ( is_string ( $ value ) && ( strpos ( $ value , '[' ) === 0 || strpos ( $ value , '{' ) === 0 || ( strpos ( $ value , '"' ) === 0 && strrpos ( $ value , '"' ) === 0 ) ) ) || is_numeric ( $ value ) ) { $ tmp = json_decode ( $ value , $ asArray ) ; if ( json_last_error ( ) !== JSON_ERROR_NONE ) { throw CastException :: forInvalidJsonFormatException ( json_last_error ( ) ) ; } } } return $ tmp ; }
Cast as JSON

@param mixed   $value
@param boolean $asArray

@return mixed
@throws \CodeIgniter\Exceptions\CastException
Cast as JSON