Req #75400 [Ana]: Already As JSON
| From: | kelunik@php.net | Date: | Tue, 24 Oct 2017 08:45:31 +0000 |
| Subject: | Req #75400 [Ana]: Already As JSON | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-212257@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=75400&edit=1
ID: 75400
Updated by: kelunik@php.net
Reported by: jwalton at aretehs dot com
Summary: Already As JSON
Status: Analyzed
Type: Feature/Change Request
Package: JSON related
Operating System: Any
PHP Version: 7.0.24
-Assigned To:
+Assigned To: pollita
Block user comment: N
Private report: N
New Comment:
Assigning to you, pollita, because you plan to work on it.
Previous Comments:
------------------------------------------------------------------------
[2017-10-23 23:57:37] pollita@php.net
That's not unreasonable. I'll propose it to the list and see about getting it into 7.3.
------------------------------------------------------------------------
[2017-10-17 19:55:11] jwalton at aretehs dot com
Description:
------------
Ability for an object to specify that it already is encoded.
Example, data returned from a database may already be in JSON format, so it seems pretty pointless
to decode it, only to re-encode it in another object.
It could be as simple as adding a new function maybe, like, jsonRawSerialize() or something.
My issue is that sometimes the the json is over 200k and it adds quite a bit of extra CPU cycles.
Test script:
---------------
// Example
class MyJSON {
public function jsonSerialize() {
return '{"myobject":true}';
}
}
print json_encode((object)[
"result" => new MyJSON()
]);
// should print
// {"result"=>{"myobject"=>true}}
//
//right now you have to do
class MyJSON2 {
public function jsonSerialize() {
return json_decode('{"myobject":true}');
}
}
print json_encode((object)[
"result" => new MyJSON2()
]);
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=75400&edit=1