3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array = [ 'field1' => 'this one is ok, "double quotes" are escaped automatically', 'field2' => 'But line breaks are not and so they ruin json' ]; echo str_replace(PHP_EOL,"\n",json_encode($array));

preferences:
29.86 ms | 405 KiB | 5 Q