Re: [RFC][Draft] Add json_encode indent parameter

From: Date: Mon, 07 Jun 2021 10:52:46 +0000
Subject: Re: [RFC][Draft] Add json_encode indent parameter
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-114764@lists.php.net to get a copy of this message
On Thu, Jun 3, 2021 at 6:11 PM Timon de Groot <tdegroot96@gmail.com> wrote:

> Hi internals,
>
> I'd like to present my RFC for adding the indent parameter to the
> json_encode function:
>    https://wiki.php.net/rfc/json_encode_indentation
>
> The string|int $indent = 4 parameter adds the ability to specify the
> indentation for
> the JSON encoder. Amount of spaces can be specified by a number and a
> string can be
> specified to set a custom indentation like \t or whatever.
>
> As this is my first RFC (and contribution) for PHP, I'm all kind of new
> to the process, standards, etc.
> Please let me know if I could do something better.
>
> Looking forward to feedback/input on the RFC.
>

As has been brought up in
https://github.com/php/php-src/pull/7093#issuecomment-855170601,
the string
version of the $indent parameter allows you to create invalid JSON,
something that json_encode() does not currently allow. I tend to agree that
it would make sense to validate that the indent only contains whitespace
characters, and not 🚀.

Regards,
Nikita


Thread (3 messages)

« previous php.internals (#114764) next »