Process the JSON Validations.

@param  string $file

@return string
773612
protected function processJSONValidations($file)
    {
        $json = File::get($file);
        $fields = json_decode($json);

        if (!property_exists($fields, 'validations')) {
            return '';
        }

        $validationsString = '';
        foreach ($fields->validations as $validation) {
            $validationsString .= $validation->field . '#' . $validation->rules . ';';
        }

        $validationsString = rtrim($validationsString, ';');

        return $validationsString;
    }
743535
public function getAllowed($file)
    {
        $commands = array();

        foreach ($this->getHandlers() as $id => $command) {
            if ($this->isAllowed($command, $file)) {
                $commands[$id] = $command;
            }
        }

        return $commands;
    }
1090565
public static function loadFile($file)
    {
        $json = new Json();

        return self::create($json->decodeFile($file), $json);
    }
849407
public function assetsAdd($file)
    {
        $resource = '/assets.json';

        $parameters = array(
            'file' => '@' . $file,
        );

        // Create request
        $data = $this->auth->request(
            'POST',
            $resource,
            $parameters
        );

        return $data;
    }
1344731
private function validateFileStructure(array &$file)
    {
        if (false === array_key_exists(self::TODO_FINDER, $file)) {
            throw new FileParserException(
                sprintf(
                    'Provided YAML file does not compile with the required format. '
                    .'Expected \'%s\' key to be present but none was found.',
                    self::TODO_FINDER
                )
            );
        }

        $this->assertYamlKey($file[self::TODO_FINDER], self::TOTAL_ALLOWED);
        $this->assertYamlKey($file[self::TODO_FINDER], self::EXPRESSIONS);
    }
1014428
protected function readConfigurationFile($file)
    {
        if (! file_exists($file)) {
            throw InvalidSetupException::confNotFound($file);
        }
        if (! $json = file_get_contents($file)) {
            throw InvalidSetupException::confNotReadable($file);
        }
        if (! $config = json_decode($json)) {
            throw InvalidSetupException::confNotJson($file);
        }
        sodium_memzero($json);
        return $config;
    }
1260824
protected function saveCredentialJson(string $file, $data)
    {
        $content = json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PARTIAL_OUTPUT_ON_ERROR | JSON_PRETTY_PRINT);
        $this->filesystem->dumpFile($file, $content);
    }
1049308
protected function loadFile($file)
    {
        if (!stream_is_local($file)) {
            throw new InvalidArgumentException(sprintf('This is not a local file "%s".', $file));
        }

        if (!file_exists($file)) {
            throw new InvalidArgumentException(sprintf('The service file "%s" is not valid.', $file));
        }

        if (null === $this->jsonParser) {
            $this->jsonParser = new Json();
        }

        return $this->validate($this->jsonParser->decode(file_get_contents($file), true), $file);
    }
282716
private static function checkType(string $file): string
    {
        $parts = explode('.', $file);
        $type = array_pop($parts);

        if (!in_array($type, array_keys(self::$types))) {
            throw new LoaderException("Loader::checkType(): Could not find parser for {$file}!");
        }

        return $type;
    }
612788
public function analyze_file(string $file): array
  {
    $res = [];
    $ext = bbn\str::file_ext($file);
    if ( \in_array($ext, self::$extensions, true) && is_file($file) ){
      switch ( $ext ){
        case 'html':
          $res = $this->analyze_php($file);
          break;
        case 'php':
          $res = $this->analyze_php($file);
          break;
        case 'js':
          $res = $this->analyze_js($file);
          break;
        /*case 'json':
          $res = $this->analyze_json($file);
          break;*/
      }
    }
    return $res;
  }
332233
public static function loadFile($file, $format = null)
    {
        if (!isset($format)) {
            $ext = pathinfo($file, PATHINFO_EXTENSION);
            $format = ArrayHelper::fetch(self::$FORMATS, $ext);
            if (!isset($format)) {
                throw new \InvalidArgumentException("Cannot infer format from file '{$file}'");
            }
        }
        if ($format == 'json') {
            return json_decode(file_get_contents($file), true);
        } elseif ($format == 'yaml') {
            return Yaml::parse(file_get_contents($file));
        } elseif ($format == 'php') {
            return require($file);
        } else {
            throw new \InvalidArgumentException("Invalid format '{$format}'");
        }
    }
44893
public function read($file)
    {
        $file = '/data/' . $file;

        /**
         * @todo validate that $file is a string
         */

        $result = [];

        $ext = pathinfo($file, PATHINFO_EXTENSION);

        if (isset($this->converters[$ext])) {

            $meta = [];

            $content = '';

            $file_contents = $this->source_filesystem->read($file);

            if ($file_contents) {

                $parts = preg_split('/\-{3}/', $file_contents, 3);

                if (count($parts) === 3) {

                    $meta = $parts[1] ?: [];

                    $content = $parts[2];
                } else {

                    $content = $file_contents;
                }

                $result = $this->yaml->parse($meta);

                $content = $this->converters[$ext]->convert($content);

                $result['content'] = trim($content);
            }
        }

        return $result;
    }
1320124
protected function validate($file)
    {
        // Check if file is valid
        if ( ! $file->isValid()) {
            return false;
        }

        $inputFile = [$this->field => $file];
        $rules     = [$this->field => $this->validationRules];

        // Validate
        $validator = Validator::make($inputFile, $rules);
        if ($validator->fails()) {
            $this->errors = $validator;

            return false;
        }

        return true;
    }
638517
public function parse($file)
	{
		$this->openFile($file);

		switch (strtolower($this->extension)) {
			case 'json':
			return json_decode($this->readFile());
			case 'ini':
			return (object)parse_ini_string($this->readFile(), true);
			case 'xml':
			return simplexml_load_string($this->readFile());
			case 'csv':
			return array_map(
				'str_getcsv',
				explode(PHP_EOL, trim($this->readFile()))
			);
			default:
				throw new \InvalidArgumentException(
					"{$this->extension} is not a supported extension."
				);
		}
	}
1211887
private function validate($content, $file)
    {
        if (null === $content) {
            return $content;
        }

        if (!is_array($content)) {
            throw new \InvalidArgumentException(sprintf('The service file "%s" is not valid.', $file));
        }

        foreach (array_keys($content) as $namespace) {
            if (in_array($namespace, ['imports', 'parameters'])) {
                continue;
            }
        }

        return $content;
    }
1127577
def validate_json(file):
    """"""
    max_file_size = current_app.config.get(
        'PREVIEWER_MAX_FILE_SIZE_BYTES', 1 * 1024 * 1024)
    if file.size > max_file_size:
        return False

    with file.open() as fp:
        try:
            json.loads(fp.read().decode('utf-8'))
            return True
        except:
            return False
53263
protected static function getMaps($file)
    {
        $maps = json_decode(File::get($file), true);

        if (is_null($maps)) {
            throw new Exception('The existing mapping file contains invalid json string. Please fix the file then try again');
        }

        return $maps;
    }