Tired of JSON's super strict syntax? Then relaxed JSON if for you.
- supports comments in all forms
// my comment
,/* my comment */
- ignores trailing commas at the end of an array or object
- throws an Exception when the json is invalid
- zero dependencies
composer require 8ctopus/relaxed-json
use Oct8pus\RelaxedJson;
$json = <<<JSON
{
// maximum requests per hour
"throttleThreshold": 300,
}
JSON;
var_dump(RelaxedJson::decode($json, true));
array(1) {
'name' =>
string(20) "8ctopus/relaxed-json"
}
$json = <<<JSON
{
"throttleThreshold" => 300,
}
JSON;
// throws RelaxedJsonException Syntax error
RelaxedJson::decode($json, true);
This library is are repack with improvements of the original work from https://github.com/etconsilium/php-json-fix
composer test
composer fix
composer fix-risky