for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Noodlehaus\Parser;
use Noodlehaus\Exception\ParseException;
/**
* JSON parser
*
* @package Config
* @author Jesus A. Domingo <[email protected]>
* @author Hassan Khan <[email protected]>
* @author Filip Š <[email protected]>
* @link https://github.com/noodlehaus/config
* @license MIT
*/
class Json implements ParserInterface
{
* {@inheritDoc}
* Loads a JSON string as an array
* @throws ParseException If there is an error parsing the JSON string
public function parse($config, $filename = null)
$data = json_decode($config, true);
if (json_last_error() !== JSON_ERROR_NONE) {
$error_message = 'Syntax error';
if (function_exists('json_last_error_msg')) {
$error_message = json_last_error_msg();
}
$error = [
'message' => $error_message,
'type' => json_last_error(),
'file' => $filename,
];
throw new ParseException($error);
return $data;
public static function getSupportedExtensions()
return ['json'];