json_encode

Supported Versions: PHP 5 >= 5.2.0, PHP 7, PHP 8, PECL json >= 1.2.0
Returns the JSON representation of a value
<?php json_encode(mixed $value, int $flags = 0, int $depth = 512): string|false
<?php if (isset($_GET['json'])) {

    header('Content-Type: application/json');

    echo json_encode(['Hello' => '🌍']);

    exit(0);

}
<?php     echo "$region\n";

}



file_put_contents(__DIR__ . '/../../layers.json', json_encode($export, JSON_PRETTY_PRINT));



echo "Done\n";
<?php         }, $arguments);



        try {

            $result = $lambda->invoke($function, json_encode(implode(' ', $arguments)));

        } catch (InvocationFailed $e) {

            $io->getErrorStyle()->writeln('<info>' . $e->getInvocationLogs() . '</info>');

            $io->error($e->getMessage());
<?php             $io->writeln('<info>Logs:</info>');

            $io->write('<comment>' . $result->getLogs() . '</comment>');

            $io->writeln('<info>Lambda result payload:</info>');

            $io->writeln(json_encode($payload, JSON_PRETTY_PRINT));

            return 1;

        }
<?php         $this->logEnd($startTime, $io, $requestId);


        $io->block(json_encode($result, JSON_THROW_ON_ERROR | JSON_PRETTY_PRINT), null, 'fg=black;bg=green', '', true);



        return 0;

    }
<?php         $request->setServerPort($event->getServerPort());

        $request->setCustomVar('PATH_INFO', $event->getPath());

        $request->setCustomVar('QUERY_STRING', $event->getQueryString());

        $request->setCustomVar('LAMBDA_INVOCATION_CONTEXT', json_encode($context));

        $request->setCustomVar('LAMBDA_REQUEST_CONTEXT', json_encode($event->getRequestContext()));



        $contentType = $event->getContentType();
<?php         $request->setCustomVar('PATH_INFO', $event->getPath());

        $request->setCustomVar('QUERY_STRING', $event->getQueryString());

        $request->setCustomVar('LAMBDA_INVOCATION_CONTEXT', json_encode($context));

        $request->setCustomVar('LAMBDA_REQUEST_CONTEXT', json_encode($event->getRequestContext()));



        $contentType = $event->getContentType();

        if ($contentType) {
<?php         echo $invocationId . "\tInvoke Error\t" . json_encode($errorFormatted) . PHP_EOL;




        $url = "http://{$this->apiUrl}/2018-06-01/runtime/invocation/$invocationId/error";
<?php     private function postJson(string $url, $data): void

    {

        $jsonData = json_encode($data);

        if ($jsonData === false) {

            throw new Exception(sprintf(

                "The Lambda response cannot be encoded to JSON.\nThis error usually happens when you try to return binary content. If you are writing an HTTP application and you want to return a binary HTTP response (like an image, a PDF, etc.), please read this guide: https://bref.sh/docs/runtimes/http.html#binary-requests-and-responses\nHere is the original JSON error: '%s'",
<?php         $response = new HttpResponse('');




        self::assertEquals('{"isBase64Encoded":false,"statusCode":200,"headers":{},"body":""}', json_encode($response->toApiGatewayFormat()));

        self::assertEquals('{"cookies":[],"isBase64Encoded":false,"statusCode":200,"headers":{},"body":""}', json_encode($response->toApiGatewayFormatV2()));

    }
<?php         self::assertEquals('{"isBase64Encoded":false,"statusCode":200,"headers":{},"body":""}', json_encode($response->toApiGatewayFormat()));

        self::assertEquals('{"cookies":[],"isBase64Encoded":false,"statusCode":200,"headers":{},"body":""}', json_encode($response->toApiGatewayFormatV2()));

    }
<?php     {

        $psr7Response = new Response(404, [

            'Content-Type' => 'application/json',

        ], json_encode(['foo' => 'bar']));



        $response = Psr7Bridge::convertResponse($psr7Response);

        self::assertSame([
<?php             'headers' => [

                'Content-Type' => 'application/json',

            ],

            'body' => json_encode(['foo' => 'bar']),

        ], $response->toApiGatewayFormat());

    }
<?php if ($_GET['extensions'] ?? false) {

    header('Content-Type: application/json');

    echo json_encode(get_loaded_extensions(), JSON_PRETTY_PRINT);

    return;

}
<?php if ($_GET['php-config'] ?? false) {

    header('Content-Type: application/json');

    echo json_encode(ini_get_all(null, false), JSON_PRETTY_PRINT);

    return;

}