Reads json file.

@throws \RuntimeException
498294
public function read()
    {
        if (!file_exists($this->path)) {
            throw new \RuntimeException('Could not read ' . $this->path);
        }
        return file_get_contents($this->path);
    }
993296
public function json()
    {
        $json = json_decode($this->getBody(), true);
        if ($json === null) {
            throw new RuntimeException(sprintf(
                "Can't decode response as JSON: %s",
                function_exists('json_last_error_msg')?
                    json_last_error_msg():
                    'Error code '.json_last_error()
            ));
        }
        return $json;
    }
1340936
public static function fromJson($jsonFile)
    {
        if (!is_file($jsonFile) && !is_readable($jsonFile)) {
            throw new \RuntimeException("Either '$jsonFile' is not a file or cannot access it");
        }
        $content = file_get_contents($jsonFile);
        if (!$content) {
            throw new \RuntimeException("Cannot load empty JSON file '$jsonFile'");
        }
        $json = json_decode($content, true);
        if (!$json) {
            throw new \RuntimeException("Could not parse JSON from '$jsonFile'");
        }
        return new \DataFilter\Profile($json);
    }
590028
def _read_json_file(self):
        
        with open(self.json_uri) as metadata_file:
            try:
                metadata = json.load(metadata_file)
                return metadata
            except ValueError:
                message = tr('the file %s does not appear to be valid JSON')
                message = message % self.json_uri
                raise MetadataReadError(message)
721984
def read_json(self):
        
        with reading_ancillary_files(self):
            if self.json_uri is None:
                metadata = self._read_json_db()
            else:
                metadata = self._read_json_file()
            if 'properties' in metadata:
                for name, prop in list(metadata['properties'].items()):
                    try:
                        self.set(prop['name'], prop['value'], prop['xml_path'])
                    except KeyError:
                        # we just skip if we don't have something, we want
                        # to have as much as possible read from the JSON
                        pass
        return metadata
1275519
public function renderView() {
		header('Content-Type: application/json;charset=utf-8');
		$json = json_encode($this->getViewVariables());
		if ($json) {
			echo $json;
		} else {
			throw new \RuntimeException($this->getEncodeErrors()[json_last_error()]);
		}
	}
659190
protected function readSchema(): \stdClass
    {
        $schema = $this->getEmptyResult();

        try {
            $schema = $this->getSchema()->read();
        } catch (InvalidArgumentException $e) {
            $this->errors[] = $e->getMessage();

            throw new JsonValidationException("Schema file `{$this->schema->getSchemaPath()}` cannot be read", 0, $e);
        }

        return $schema;
    }
390852
public function read(bool $assoc = false)
    {
        $json = json_decode(parent::read(), $assoc);
        if (json_last_error() !== JSON_ERROR_NONE) {
            throw new RuntimeException('Invalid json file');
        }
        return $json;
    }
669217
public function decode($data)
    {
        $decoded = @json_decode($data, $this->getDecodeAssoc(), $this->getDecodeDepth(), $this->getDecodeOptions());

        if (null === $decoded && json_last_error() !== JSON_ERROR_NONE) {
            throw new \RuntimeException('Decoding JSON failed: ' . json_last_error_msg());
        }

        return $decoded;
    }
877663
private function loadFile(string $filename) : array
    {
        Assertion::file($filename, 'File "' . $filename . '" does not exist.');
        Assertion::readable($filename, 'File "' . $filename . '" is not readable.');

        /** @var string $fileContent */
        $fileContent = file_get_contents($filename);

        Assertion::string($fileContent);

        if (preg_match('/[^ -~\s]/', $fileContent)) {
            throw new \RuntimeException('File "' . $filename . '" contains Non-ASCII-Characters.');
        }

        $jsonParser = new JsonParser();

        try {
            return $jsonParser->parse($fileContent, JsonParser::DETECT_KEY_CONFLICTS | JsonParser::PARSE_TO_ASSOC);
        } catch (ParsingException $e) {
            throw new \RuntimeException(
                'File "' . $filename . '" had invalid JSON.',
                0,
                $e
            );
        }
    }
766060
private function open()
    {
        if (null === ($this->handle = fopen($this->file, 'rb'))) {
            $this->handle = null;

            throw new RuntimeException(
                sprintf(
                    'The file "%s" could not be opened for reading.',
                    $this->file
                )
            );
        }
    }
121555
public static JSONObject readJSONObject(File file, Charset charset) throws IORuntimeException {
		return parseObj(FileReader.create(file, charset).readString());
	}
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;
    }
1353174
private function readStoredRoutineMetadata(): void
  {
    if (file_exists($this->phpStratumMetadataFilename))
    {
      $this->phpStratumMetadata = (array)json_decode(file_get_contents($this->phpStratumMetadataFilename), true);
      if (json_last_error()!=JSON_ERROR_NONE)
      {
        throw new RuntimeException("Error decoding JSON: '%s'.", json_last_error_msg());
      }
    }
  }
773879
def _read_json_file(self, json_file):
        

        self.log.debug("Reading '%s' JSON file..." % json_file)

        with open(json_file, 'r') as f:
            return json.load(f, object_pairs_hook=OrderedDict)
1127460
private function readSourceFile()
    {
        if (null == $this->source) {
            $path = $this->getInputFile();
            if (null === $path) {
                throw new \RuntimeException("View input file not specified.");
            }
            try {
                $this->source = \file_get_contents($path);
            } catch (\Exception $e) {
                throw new \RuntimeException(sprintf('View "%s" file can not be read', $path));
            }
        }
        return $this->source;
    }
1333527
protected function loadComposerJson()
    {
        $composerJsonPath = $this->getComposerJsonPath();

        if (! File::exists($composerJsonPath)) {
            throw new FileNotFoundException('composer.json does not exist');
        }

        $composerJsonContent = File::get($composerJsonPath);
        $composerJson = json_decode($composerJsonContent, true);

        if (! is_array($composerJson)) {
            throw new RuntimeException("Invalid composer.json file [$composerJsonPath]");
        }

        return $composerJson;
    }