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
json_encode(mixed $valueint $flags 0int $depth 512): string|false
if (isset($_GET['json'])) {

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

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

    exit(
0);

}
    echo "$region\n";

}



file_put_contents(__DIR__ '/../../layers.json'json_encode($exportJSON_PRETTY_PRINT));



echo 
"Done\n";
        }, $arguments);



        try {

            
$result $lambda->invoke($functionjson_encode(implode(' '$arguments)));

        } catch (
InvocationFailed $e) {

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

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

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

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

            
$io->writeln(json_encode($payloadJSON_PRETTY_PRINT));

            return 
1;

        }
        $this->logEnd($startTime$io$requestId);


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



        return 
0;

    }
        $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();
        $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) {
        echo $invocationId "\tInvoke Error\t" json_encode($errorFormatted) . PHP_EOL;




        
$url "http://{$this->apiUrl}/2018-06-01/runtime/invocation/$invocationId/error";
    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'",
        $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()));

    }
        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()));

    }
    {

        
$psr7Response = new Response(404, [

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

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



        
$response Psr7Bridge::convertResponse($psr7Response);

        
self::assertSame([
            'headers' => [

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

            ],

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

        ], 
$response->toApiGatewayFormat());

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

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

    echo 
json_encode(get_loaded_extensions(), JSON_PRETTY_PRINT);

    return;

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

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

    echo 
json_encode(ini_get_all(nullfalse), JSON_PRETTY_PRINT);

    return;

}