PHP 8.3: Bringing Improved JSON Validation
The new json_validate
function in PHP 8.3 brings needed functionality for efficient JSON validation.
Created May 17, 2023 - Last updated: May 17, 2023
While PHP 8.3 is planned for release in mid-to-late November 2023, among the list of changes is a new JSON validation function, json_validate
. This new function has the possibility to further increase performance when dealing with large volumes of JSON encoded data in applications.
In previous versions you had to decode the JSON encoded data fully which may unnecessarily use memory and time if you aren’t interested in the data.
# In PHP 8.2 and earlier you use the `json_decode` function on the JSON
# encoded data which used memory and time unnecessary for just validation.
json_decode($json)
$isValid = json_last_error() === JSON_ERROR_NONE;
# In PHP 8.3 and later the new `json_validate` function will use less
# memory and be quicker for validating well formed JSON encoded data.
$isValid = json_validate($json);
While this single addition is not a huge improvement, these incremental enhancements with each release have continued to improve the PHP experience overall.
When PHP 8.3 is finally released I plan to benchmark the new function and post the results here.