returns a JSON string of $data array.

@param array $data
@return Response
501151
public function asJson(array $data)
    {
        $stream = StreamFactory::string(json_encode($data));
        return new Response($stream, self::OK, ['Content-Type' => 'application/json']);
    }
1073125
public function encode(array $data): string
    {
        $options = JSON_PRESERVE_ZERO_FRACTION | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES;
        if ($this->prettyPrint) {
            $options = $options | JSON_PRETTY_PRINT;
        }

        return json_encode($data, $options);
    }
559589
public static function encodeData($data)
    {
        if (\is_array($data)) {
            foreach ($data as $key => $value) {
                $data[$key] = \urlencode($value);
            }

            return $data;
        }

        return \urlencode($data);
    }
849414
public function deserialize(array $data)
    {
        $original = $data;
        $this->deserializeTos($data);
        $data = $this->getJavascriptsData($data);
        $data = $this->getLogoData($data);
        unset($data['tos']['text']);
        //maybe move this somewhere else
        unset($data['archives']);

        $data = array_merge($this->serialize([Options::SERIALIZE_MINIMAL]), $data);
        ksort($data);
        $data = json_encode($data, JSON_PRETTY_PRINT);

        file_put_contents($this->filePath, $data);

        return $original;
    }
1156357
private static function parseRawHttpRequest(array &$data) {

    	if(false === isset($_SERVER['CONTENT_TYPE'])) {
    		$_SERVER['CONTENT_TYPE'] = '';
    	}

		$input = static :: getBody();

		preg_match('/boundary=(.*)$/', $_SERVER['CONTENT_TYPE'], $matches);

		if(0 === count($matches)) {

			$json = @json_decode($input, true);

			if(true === (json_last_error() == JSON_ERROR_NONE)) {

				$data = $json;
				return $json;
			}

			parse_str(urldecode($input), $data);
			return $data;
		}

		$boundary 	= $matches[1];
		$blocks 	= preg_split("/-+$boundary/", $input);

		array_pop($blocks);

		foreach($blocks as $id => $block) {

			if('' === $block) {
				continue;
			}

			if(false !== strpos($block, 'application/octet-stream')) {
			
				preg_match("/name=\"([^\"]*)\".*stream[\n|\r]+([^\n\r].*)?$/s", $block, $matches);
				$data['files'][$matches[1]] = $matches[2];
			}
			else {

				preg_match('/name=\"([^\"]*)\"[\n|\r]+([^\n\r].*)?\r$/s', $block, $matches);
				$data[$matches[1]] = $matches[2];
			}
		}
	}
1009679
public static function buildEnEmojiData(array $data)
    {
        foreach ($data as $key => $value) {
            if (is_array($value)) {
                $data[$key] = self::buildEnEmojiData($value);
            } elseif (is_string($value)) {
                $data[$key] = self::emojiEncode($value);
            } else {
                $data[$key] = $value;
            }
        }
        return $data;
    }
175079
protected function createJsonResponse(array $data, array $config)
    {
        if (! \is_null($uses = $config['uses'] ?? null)) {
            $data = $data[$uses] ?? [];
        }

        if ($data instanceof Arrayable) {
            $data = $data->toArray();
        }

        $data = \array_map([$this, 'transformToArray'], $data);

        return function () use ($data, $config) {
            return \json_encode($data, $config['encoding'] ?? 0);
        };
    }
346816
public function respond(array $data = [], array $headers = []): JsonResponse
    {
        $meta = [
            'meta' => [
                'server_time' => time(),
                'server_timezone' => date_default_timezone_get(),
                'api_version' => 'v1',
            ],
        ];

        return response()->json(array_merge($data, $meta), $this->getStatusCode(), $headers);
    }
800361
public static function json_encode(array $data)
    {
        $json = @json_encode($data);
        if (json_last_error() !== JSON_ERROR_NONE) {
            throw new \Exception(
                sprintf('An error occurred while trying to encode data to JSON [code "%s"]!', json_last_error())
            );
        } else {
            $data = $json;
        }
        return $data;
    }
613870
protected function encode(array $data)
    {

        foreach ($data as $key => $value) {
            if (is_string($value)) {
                $data[$key] = base64_encode($value);
            }
        }

        return $data;
    }
87364
public function responseJson($data)
    {
        $response = \Yii::$app->response;
        $response->format = Response::FORMAT_JSON;
        $response->data = $data;

        return $data;
    }
420306
protected function jsonResponse($data = array())
    {
        $this->view->disable();
        $this->response->setContentType('application/json', 'UTF-8');

        return $this->response->setJsonContent($data);
    }
1159660
private function convertToJson($data)
    {
        if (is_array($data)) {
            return json_encode($data);
        }

        if ($data instanceof Jsonable) {
            return $data->toJson();
        }

        if ($data instanceof Arrayable) {
            return json_encode($data->toArray());
        }

        return null;
    }
698318
private function toArrayData(array $data){
		foreach ($data as $key => &$val){

			if (is_object($val)){
				if ($val instanceof self){
					$val = $val->toArray();
				}
				elseif ($val instanceof DateTimeInterface) {
					$val = $val->format(self::DATE_FORMAT);
				}
				else {
					$val = (array) $val;
				}
			}

			if (is_array($val)){
				$val = $this->toArrayData($val);
			}
		}

		return $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;
    }
135666
protected function decodeJson($data) {
        if (strpos($data, 'callback') !== false) {
            $leftPos = strpos($data, '(');
            $rightPos = strrpos($data, ')');
            $data = substr($data, $leftPos + 1, $rightPos - $leftPos -1);
        }
        return Json::decode($data);
    }
1113101
protected function getString($data)/*# : string */
    {
        if (is_scalar($data)) {
            return strval($data);
        } elseif (is_array($data)) {
            return 'ARRAY[' . count($data) . ']';
        } elseif (is_object($data)) {
            return $this->getObjectString($data);
        } else {
            return 'TYPE: ' . gettype($data);
        }
    }