Re: json_encode indent parameter
| From: | Jordi Boggiano | Date: | Fri, 04 Jun 2021 06:24:49 +0000 |
| Subject: | Re: json_encode indent parameter | ||
| References: | 1 2 3 4 5 6 7 8 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-114725@lists.php.net to get a copy of this message | ||
On 03/06/2021 18:03, Timon de Groot wrote:
On 3-6-2021 17:53, Ayesh Karunaratne wrote:Hi Timon, Thank you for this RFC. I think theBasically, yes. Withstring|int $indentapproach is great 🚀! Reading the PR, it looks like$indent=0is essentially turning off pretty-print, which I think is intuitive.$indent=0, no indentation will take place but new lines will still be added.Do you plan to add any sort of validation on negative integers? Perhaps throw aGood question. Personally I'd prefer clamping $indent to 0 when it reaches below 0. But I'd like to hear about what other particpants think about such behavior. IMO the JS spec is quite reasonable there, and I would say copying it 1:1 would be fine:\ValueErrorexception on $indent < 0?
If this is a Number, it indicates the number of space characters to use as white space; this number is capped at 10 (if it is greater, the value is just 10). Values less than 1 indicate that no space should be used.
If this is a String, the string (or the first 10 characters of the string, if it's longer than that) is used as white space. If this parameter is not provided (or is null), no white space is used.Best, Jordi -- Jordi Boggiano @seldaek - https://seld.be