← All built-ins / json_encode()

json_encode()

json_encode(...$args): string

Parameters

NameTypeDescription
$vmixedvalue to encode
$flagsintJSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_NUMERIC_CHECK | JSON_FORCE_OBJECToptional

Return value

JSON string.

Example

echo json_encode(["name" => "holy", "n" => 42, "ok" => true]), "
";
echo json_encode(["b" => [1, 2]], JSON_PRETTY_PRINT), "
";
{"name":"holy","n":42,"ok":true}
{
    "b": [
        1,
        2
    ]
}

See also

json_decode()serialize()