zumba/json-serializer

Allow JSON_PRETTY_PRINT

williamdes opened this issue · 5 comments

protected function calculateEncodeOptions()

At phpMyAdmin while adding your lib on our tests I had to hack this to enable pretty print because reading diffs on PRs is very important for us.

        $serializer = new JsonSerializer();
        $encoded = $serializer->serialize($test);
        $encoded = json_encode(json_decode($encoded), JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_PRESERVE_ZERO_FRACTION);

Hi @jrbasso
Should I make a PR ?

@williamdes Sorry, I totally missed this issue. I'm sorry.

I think just adding the JSON_PRETTY_PRINT on that list would cause backward incompatibility and a possibility of break some systems that expect always one line. Also, it goes inverse as optimization.
However, I think the case is valid and maybe adding a new method to specify the encoding modifiers is a good way to handle it, so it becomes optional and whoever set these flags will expect a different output format.

I think just adding the JSON_PRETTY_PRINT on that list would cause backward incompatibility and a possibility of break some systems that expect always one line. Also, it goes inverse as optimization.
However, I think the case is valid and maybe adding a new method to specify the encoding modifiers is a good way to handle it, so it becomes optional and whoever set these flags will expect a different output format.

Sure !
We will be happy to use this new function as for us the diff between JSON files needs to be visible

Here is the old diffs, totally un-readable PHP serialize data: phpmyadmin/sql-parser@b60d7e7

And here you can see that with you lib and pretty json it make quite a difference in changes tracking !
See: phpmyadmin/sql-parser@e0ba76f#diff-5223b8b0039f0b42219f7e98df65f2f0b2595a3a3880a5376502a25d1679be73