Re: json_encode indent parameter

From: Date: Thu, 03 Jun 2021 11:35:20 +0000
Subject: Re: json_encode indent parameter
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-114708@lists.php.net to get a copy of this message
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

« previous php.internals (#114708) next »