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

From: Date: Tue, 15 Jun 2021 21:46:23 +0000
Subject: Re: [RFC][Draft] Add json_encode indent parameter
References: 1 2  Groups: php.internals 
Request: Send a blank email to internals+get-114896@lists.php.net to get a copy of this message
On Mon, Jun 7, 2021 at 11:53 AM Nikita Popov <nikita.ppv@gmail.com> wrote:

> 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 🚀.
>
>
I agree with this, it should validated to be also consistent with UTF-8
validation. For example if it's not valid utf8, it returns false (unless
ignoring or substitution is enabled). In any case it never returns invalid
json atm. I don't think it's a good idea to break that assumption.

Cheers

Jakub


Thread (3 messages)

« previous php.internals (#114896) next »