Skip to content

json_encode: implemented JSON_PRETTY_PRINT, json_*: fixed float point encode/decode#775

Open
comm644 wants to merge 1 commit intoVKCOM:masterfrom
comm644:comm644/json
Open

json_encode: implemented JSON_PRETTY_PRINT, json_*: fixed float point encode/decode#775
comm644 wants to merge 1 commit intoVKCOM:masterfrom
comm644:comm644/json

Conversation

@comm644
Copy link

@comm644 comm644 commented Mar 10, 2023

Hi!

Please merge this changes for json_encode/decode. and add unit-tests.

  1. Implemented JSON_PRETTY_PRINT

test case:

<?php


echo json_encode([
        "object" =>[ 
                "a"=>[
                        "value" => 10,
                        "array" => [10,2,3,4,5]
                ],
                "b"=>[
                        "value" => 10,
                        "array" => [10,2,3,4,5],
                        "strings" => ["some stringA", "some string B"]
                ]
        ]
], JSON_PRETTY_PRINT);
  1. Fixed float point encoding decoding when locale not "C"

test case:

<?php

#ifndef KPHP
$locale = 'ru_RU.UTF-8';
setlocale(LC_ALL, $locale);
putenv('LC_ALL=' . $locale);
#endif

$mixed = [
        "value"=> 10.1896
];

$json = json_encode($mixed);


echo "encoded: \n". $json ."\n";

echo "decoded: \n";
print_r( json_decode($json, true) );

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant