Read and parse a json file

@param string $jsonFilePath : The path to the file to read

@return mixed Json parsed datas

@throws \Exception If the file is not found or for a json parser error
192424
protected static function readJsonFile(string $jsonFilePath)
    {
        if (!file_exists($jsonFilePath)) {
            throw new Exception(
                'File '.$jsonFilePath.' not found.',
                self::ERR_FILE_NOT_FOUND
            );
        }

        $infos = json_decode(file_get_contents($jsonFilePath));
        if ($infos === null) {
            throw new Exception(
                json_last_error_msg(),
                self::ERR_JSON_PARSE
            );
        }

        return $infos;
    }
1016849
function loadJSONConfigFile(filePath) {
    try {
        return JSON.parse(stripComments(readFile(filePath)));
    }
    catch (e) {
        e.message = `Cannot read config file: ${filePath}\nError: ${e.message}`;
        throw e;
    }
}
518968
def _loadfilepath(self, filepath, **kwargs):
        
        with open(filepath, "r") as f:
            data = json.load(f, **kwargs)
        return data
756828
def __parse_json_file(self, file_path):
        
        if file_path == '' or os.path.splitext(file_path)[1] != '.json':
            raise IOError('Invalid Json file')

        with open(file_path) as json_file:
            self._raw_data = json.load(json_file)

        self._json_data = copy.deepcopy(self._raw_data)
1073766
public static function parseFile($filepath)
    {
        if (!is_file($filepath)) {
            throw new \RuntimeException('File not found: ' . $filepath);
        }

        if (!$filedata = static::readFiledata($filepath)) {
            throw new \RuntimeException('Error reading file: ' . $filepath);
        }

        if (!$json = self::decode($filedata)) {
            throw new \RuntimeException('Error parsing json: ' . $filepath);
        }

        return $json;
    }
1244282
def load_json_file_contents(path: str) -> str:
    
    assert isinstance(path, str)
    content = None

    file_path = os.path.abspath(path)
    content = fileutils.read_text_from_file(file_path)
    json_object = json.loads(content)
    content = json.dumps(json_object, sort_keys=True, indent=4)

    return content
730895
public function read($path)
    {
        $data = $this->readJson($path);
        $this->validator()->validate($data);

        return $this->createConfiguration($data);
    }
514101
public function jsonArray()
    {

        if (!$this->isContentType('application/json')) {
            throw new Exception('Response is not JSON');
        }

        if (empty($this->_jsonAsArray)) {
            $this->_jsonAsArray = Utils::json_parse($this->text(), true);
        }

        return $this->_jsonAsArray;

    }
656641
private function parseFile(string $path): array
    {
        $json = json_decode(file_get_contents($path), true);
        $root = dirname($path);

        $namespaces = array_merge(
            iterator_to_array($this->parseNamespaces($json['autoload']['psr-4'] ?: [], $root)),
            iterator_to_array($this->parseNamespaces($json['autoload-dev']['psr-4'] ?: [], $root))
        );
        return $namespaces;
    }
724460
public function save( $filePath ){
		$data	= array();
		foreach( $this->index() as $route ){
			$data[]	= array(
				'controller'	=> $route->getController(),
				'action'		=> $route->getAction(),
				'pattern'		=> $route->getPattern(),
				'method'		=> $route->getMethod(),
			);
		}
		return \FS_File_JSON_Writer::save( $filePath, $data, TRUE );
	}
603509
protected function parsePseudoIniFile($filepath)
    {
        $properties = array();
        if (($lines = @file($filepath)) === false) {
            throw new Exception("Unable to parse contents of $filepath");
        }
        foreach ($lines as $line) {
            $line = trim($line);
            if ($line == "" || $line{0} == '#' || $line{0} == ';') {
                continue;
            }
            $pos = strpos($line, '=');
            $property = trim(substr($line, 0, $pos));
            $value = trim(substr($line, $pos + 1));
            if ($value === "true") {
                $value = true;
            } elseif ($value === "false") {
                $value = false;
            }
            $properties[$property] = $value;
        }

        return $properties;
    }
534181
public static function decodeFromFile($path)
    {
        if (!is_file($path)) {
            throw new \Exception("File does not exist: {$path}");
        }

        $string = file_get_contents($path);

        if ($string === false) {
            throw new \Exception("Failed to read the file: {$path}");
        }

        if (!$string) {
            return [];
        }

        $array = json_decode($string, true);

        static::checkLastError();

        return $array;
    }
921208
private function getJsonException(\Exception $e)
    {
        $file = Path::makeRelative($e->getFile(), $this->app['path_resolver']->resolve('root'));

        $error = [
            'error' => [
                'type'    => get_class($e),
                'file'    => $file,
                'line'    => $e->getLine(),
                'message' => $e->getMessage(),
            ],
        ];

        return new JsonResponse($error, Response::HTTP_INTERNAL_SERVER_ERROR);
    }
611714
public Iterator<Object> iterator(String json, JsonPath jsonPath) {
        SurfingContext context = createIteratorContext(jsonPath);
        final ResumableParser resumableParser = jsonParserAdapter.createResumableParser(json, context);
        resumableParser.parse();
        return createIterator(context, resumableParser);
    }
317673
protected function importFromJson($filePath)
    {

        $this->sourceData = $json = $this->readJson($filePath);
        $data = [];
        $docs = [];
        $methods = [];
        $operations = [];

        if (!empty($json)) {

            $globalInfo = $this->readGlobalInfo($json);
            $globalTitle = $this->readGlobalTitle($globalInfo);

            $items = $json['item'];

            foreach ($items as $itemIndex => $apiGroup) {
                $apiGroupName = $this->applyFilter('GroupName', $apiGroup['name']);
                $apiGroupDescription = $this->applyFilter('GroupDescription', $apiGroup['description']);
                if (empty($docs[$apiGroupName])) {
                    $docs[$apiGroupName] = ['description' => $apiGroupDescription, 'items' => []];
                } else {
                    // group already exists
                }

                $apiGroupItems = $apiGroup['item'];
                foreach ($apiGroupItems as $apiIndex => $api) {
                    $api = $this->preProcessApi($api);

                    $commonParams = compact('api', 'apiIndex',
                        'apiGroupItems', 'apiGroup', 'operations') +
                            [
                                'groupIndex' => $itemIndex,
                                'info' => $globalInfo,
                                'allItems' => $items
                            ];

                    $operation = $this->readOperationItem($commonParams);
                    $commonParams['operation'] = $operation;

                    $commonParams['apiName'] = $apiName = $this->readApiName($commonParams);
                    $skipConfig = $this->deliberateSkips($commonParams);
                    if (($skipConfig['operation']  ?? true) !== false) {
                        $operations[$apiName] = $operation;
                    }

                    if (($skipConfig['phpDoc']  ?? ($skipConfig['docs']  ?? true)) !== false) {
                        $commonParams['phpDocMethod'] = $methods[$apiName] = $this->readPhpDocMethodItem($commonParams);
                    }
                    if (($skipConfig['mdDoc']  ?? ($skipConfig['docs']  ?? true)) !== false) {
                        $docs[$apiGroupName]['items'][$apiName] = $this->readMarkdownItem($commonParams);
                    }
                }
            }

            if (!empty($operations)) {
                $data = compact('operations');
                $data['models'] = $this->getOperationModels($operations);
            }

            $this->mdDocsData = ['title' => $globalTitle, 'groups' => $docs];
            $this->methodData = $methods;
        }

        return $data;
    }
694772
public function parse($path)
    {
        $data = json_decode(file_get_contents($path), 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();
            }
            
            throw new Exception($error_message);
        }
        return $data;
    }
969804
private function loadIndexFile(string $indexFilepath): array
    {
        $this->status = IndexInterface::STATUS_LOADED;
        return \unserialize(\file_get_contents($indexFilepath));
    }