JSON Response

@param mixed $data
@return string JSON Only for yii\web\Application, for console app returns `mixed`
970577
private function response($data)
    {
        // @codeCoverageIgnoreStart
        if (!Yii::$app instanceof \yii\console\Application) {
            \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
        }
        // @codeCoverageIgnoreEnd
        return $data;
    }
1350191
public static function EncodeJson (& $data) {
		$flags = JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_AMP |
			(defined('JSON_UNESCAPED_SLASHES') ? JSON_UNESCAPED_SLASHES : 0) |
			(defined('JSON_UNESCAPED_UNICODE') ? JSON_UNESCAPED_UNICODE : 0) |
			(defined('JSON_PRESERVE_ZERO_FRACTION') ? JSON_PRESERVE_ZERO_FRACTION : 0);
		$json = json_encode($data, $flags);
		if ($errorCode = json_last_error()) {
			$selfClass = version_compare(PHP_VERSION, '5.5', '>') ? self::class : __CLASS__;
			throw new \RuntimeException("[".$selfClass."] ".json_last_error_msg(), $errorCode);
		}
		if (PHP_VERSION_ID < 70100) {
			$json = strtr($json, [
				"\xe2\x80\xa8" => '\u2028',
				"\xe2\x80\xa9" => '\u2029',
			]);
		}
		return $json;
	}
344705
static public function decode($data)
	{
	    return json_decode($data, true) ? : ($data && $data!='\"\"' && $data !='false' ? $data : null);
	}
301612
public function stringify($data)
    {
        return array_map(function ($item) {
            return is_array($item) ? json_encode($item, JSON_OBJECT_AS_ARRAY) : (string) $item;
        }, $data);
    }
1203570
public static function encode($data): string
    {
        if (PHP_VERSION_ID >= 50400) {
            return json_encode($data, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
        }

        return json_encode($data);
    }
77472
public function decode($data)
    {
        $xml = simplexml_load_string($data, "SimpleXMLElement", LIBXML_NOCDATA);
        $json = json_encode($xml);
        $this->arrayData = json_decode($json, true);
        return $this->arrayData;
    }
1181187
public function decode($data)
    {
        $data = (string) $data;
        // skip empty strings (that cause "Syntax error"?)
        if ($data === '') {
            return null;
        }

        $data = json_decode($data, $this->options['assoc'], $this->options['depth'],
            $this->options['flags']);
        if (json_last_error() > 0) {
            $data = null;
            $this->error = json_last_error_msg() ?: 'Unknown';
        }

        return $data;
    }
657958
private function parseJsonString($data)
    {
        try {
            return json_decode($data, true);
        } catch (Exception $e) {
            throw new ConfigException($e->getMessage());
        }
    }
985337
protected function serializeItem($data) {
        if ($data instanceof IArrayable) {
            return $data->toArray();
        } else if ($data instanceof IJsonable) {
            return $data->toJson();
        } else if ($data instanceof IStringable) {
            return $data->toString();
        }

        return $data;
    }
96033
public function parse($data)
    {
        if ($data === null || !is_string($data)) {
            return array();
        }

        if (substr($data, 0, 1) !== '{' &&
            substr($data, 0, 1) !== '[') {
            return array();
        }

        return (array) json_decode($data, true);
    }
34042
private function _outputJson($data)
    {
        $data = json_encode($data);
        $this->response->setBody($data);
        $this->response->setHeader('content-type', sprintf('application/json; charset=%s', $this->application->config('encoding.output')));
    }
669217
public function decode($data)
    {
        $decoded = @json_decode($data, $this->getDecodeAssoc(), $this->getDecodeDepth(), $this->getDecodeOptions());

        if (null === $decoded && json_last_error() !== JSON_ERROR_NONE) {
            throw new \RuntimeException('Decoding JSON failed: ' . json_last_error_msg());
        }

        return $decoded;
    }
933471
protected function jsonResponse($data)
    {
        /** @var \Magento\Framework\Controller\Result\Json $resultJson */
        $resultJson = $this->resultJsonFactory->create();
        $resultJson->setHeader('Content-type', 'application/json', true);
        $resultJson->setData($data);
        return $resultJson;
    }
701080
public function encodeJson($data): string
    {
        if ($data instanceof JsonSerializable) {
            $data = $data->jsonSerialize();
        }

        $result = json_encode($this->utf8Encoding->encodeUtf8($data), 512, JSON_THROW_ON_ERROR);

        if ($result === false) {
            throw new JsonException('Json encoding failed');
        }

        return $result;
    }
826258
public function json($data, $status = 200)
    {
        $this->header('Content-Type: application/json');

        $this->statusCode($status);

        return json_encode($data);
    }
1285897
public static function createFromJsonResponse($data)
    {
        $data = json_decode($data, true);

        $stacks = array_map(function ($stack) {
            return Stack::createFromDecodedJsonResponse($stack);
        }, $data['items']);

        return new self($stacks);
    }
549179
protected function getResult($data)
    {
        if (is_array($data)) {
            header('content-type: application/json');
            return $this->cypher->encode(json_encode($data));
        }

        return $data;
    }