Hello, I have seen a similar discussion for var_export(), and the answer was basically "use a regex". E.g.:
$json = preg_replace_callback( '/^(?: {4})+/m', fn ($m) => str_repeat($indent, strlen($m[0]) / 4), json_encode($data, JSON_PRETTY_PRINT) ); That said, I wouldn't mind a new indent parameter (but note that allowing an arbitrary string [not limited to whitespace] might result in invalid JSON). Regards, -- Guilliam Xavier