Req #69422 [Com]: json_encode() needs encoding specification
Edit report at https://bugs.php.net/bug.php?id=69422&edit=1
ID: 69422
Comment by: glash dot gnome at gmail dot com
Reported by: yohgaki@php.net
Summary: json_encode() needs encoding specification
Status: Open
Type: Feature/Change Request
Package: JSON related
PHP Version: Irrelevant
Block user comment: N
Private report: N
New Comment:
Hello, I propose an incomplete solution but it may solve some problems.
Like array_intersect() we could do :
class ExpectedObject {
string $test;
float $poc;
}
$obj = json_decode_spec('{"test":1234567890.12345678, "poc":
"1Gm", "key":'val'}', ExpectedObject::class, ...);
var_dump($obj);
object(ExpectedObject)#1 {
test => (string) '1234567890.12345678'
poc => (float) 1.0
}
Regards
Previous Comments:
------------------------------------------------------------------------
[2015-04-19 22:13:04] yohgaki@php.net
Related bug
https://bugs.php.net/bug.php?id=68456
------------------------------------------------------------------------
[2015-04-10 21:57:21] yohgaki@php.net
Description:
------------
Currently, json_encode() encode PHP int/float/bool as JSON numeric(int/float) and bool. Since JSON
numeric does not map to PHP int/float as JSON numeric could be any precision, large numbers need to
be stored as "string" which is converted to JSON string.
Some "string" needed to be encoded as numeric. To do that json_encode() needs some kind of
specification to encode data as programmer intended.
http://json-schema.org/examples.html
This could be used as the specification.
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=69422&edit=1
Thread (4 messages)