PHP

Pretty-Print JSON

admin by @admin ADMIN
3d ago
May 31, 2026
Public
0 0 up · 0 down Sign in to vote
One-liner wrapper around json_encode with the right flags: indented, no escaped slashes, no escaped unicode. Use it everywhere instead of raw json_encode for human-readable output.
PHP
Raw
<?php
function jsonPretty(mixed $value): string {
    return json_encode(
        $value,
        JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_THROW_ON_ERROR
    );
}

echo jsonPretty(['name' => 'Café', 'url' => 'https://x.com/foo']);
// {
//     "name": "Café",
//     "url": "https://x.com/foo"
// }
Tags

Save your own code snippets

Create a free account and build your private vault. Share publicly whenever you want.