• Модуль: im
  • Путь к файлу: ~/bitrix/modules/im/lib/common.php
  • Класс: BitrixImCommon
  • Вызов: Common::toJson
static function toJson($array, $camelCase = true)
{
	$result = [];
	foreach ($array as $field => $value)
	{
		if (is_array($value))
		{
			$value = self::toJson($value, $camelCase);
		}
		else if ($value instanceof BitrixMainTypeDateTime)
		{
			$value = date('c', $value->getTimestamp());
		}
		else if (is_string($value) && $value && is_string($field) && in_array($field, Array('AVATAR')) && mb_strpos($value, 'http') !== 0)
		{
			$value = BitrixImCommon::getPublicDomain().$value;
		}

		if ($camelCase)
		{
			$field = lcfirst(BitrixMainTextStringHelper::snake2camel($field));
		}
		else
		{
			$field = mb_strtolower($field);
		}

		$result[$field] = $value;
	}

	return $result;
}