No longer actively maintained. I work now with NodeJS and I recommand you to take a look at json5
JSON5 parser for PHP.This library using kujirahand/JSON5-PHP as reference.
- PHP 5.5.11 or later
- Composer
- JSON extension
- mbstring extension
- Parse JSON5 string
- Parse JSON5 by file
Use composer.
Modify require directive in composer.json
.
{
"require": {
"hiroto-k/json5-php": "~1.0"
}
}
Please add require "vendor/autoload.php"
in your php file.
Example
<?php
require "vendor/autoload.php";
use HirotoK\JSON5\JSON5;
$json5_string = "{hoge: 'foo',}";
// Return 'stdClass'
$json_object = JSON5::decode($json5_string);
// Return 'array'
$json_array = JSON5::decode($json5_string, true);
$json5_file = "./tests/files/example.json5";
// Pass file name or SplFileObject.
// Return 'stdClass'
$json_object = JSON5::decodeFile($json5_file);
$json_object = JSON5::decodeFile(new SplFileObject($json5_file));
// Return 'array'
$json_array = JSON5::decodeFile($json5_file, true);
$json_array = JSON5::decodeFile(new SplFileObject($json5_file), true);