Return content in cached file in JSON format
340507
def get_item(key):
    """"""
    CACHED_KEY_FILE = os.path.join(CURRENT_DIR, key)

    try:
        return json.loads(open(CACHED_KEY_FILE, "rb").read().decode('UTF-8'))["_"]
    except (IOError, ValueError):
        return None
1372566
function _loadJSON(file) {
  try {
    var data = _fs2.default.readFileSync(file);
  } catch (e) {
    throw new Error(file + " expected to be in JSON format");
  }
  return JSON.parse(data);
}
921631
def _get_json(self, url):
        
        self.log.info(u"/GET " + url)
        r = requests.get(url)
        if hasattr(r, 'from_cache'):
            if r.from_cache:
                self.log.info("(from cache)")
        if r.status_code != 200:
            throw_request_err(r)

        return r.json()
1009450
function(src) {
    var cache;

    try {
      cache = fs.existsSync(src) ? file.readJSON(src) : undefined;
    } catch (e) {
      debug(e);
    }

    // Progressively upgrade `cache`, which is one of:
    // empty
    // {}
    // { file: size [,...] }
    // { "": { tips: { label: SHA1, ... } }, label: { file: size, ... }, ... }
    // { "": { version: 0.4, tips: { label: SHA1, ... } },
    //   label: { file: { "": size, compressor: size, ... }, ... }, ... }
    if (typeof cache !== "object") {
      cache = undefined;
    }
    if (!cache || !cache[""]) {
      // If promoting cache to dictionary, assume that data are for last run
      cache = _.zipObject(["", lastrun], [{ version: 0, tips: {} }, cache]);
    }
    if (!cache[""].version) {
      cache[""].version = 0.4;
      _.forEach(cache, function(sizes, label) {
        if (!label || !sizes) {
          return;
        }

        // If promoting sizes to dictionary, assume that compressed size data are indicated by suffixes
        Object.keys(sizes)
          .sort()
          .forEach(function(file) {
            var parts = file.split("."),
              prefix = parts.shift();

            // Append compressed size data to a matching prefix
            while (parts.length) {
              if (typeof sizes[prefix] === "object") {
                sizes[prefix][parts.join(".")] = sizes[file];
                delete sizes[file];
                return;
              }
              prefix += "." + parts.shift();
            }

            // Store uncompressed size data
            sizes[file] = { "": sizes[file] };
          });
      });
    }

    return cache;
  }
689156
public function load_cached_contents(){
		$caches = json_decode('{}');
		$path_json = $this->exdb->conf()->path_cache_dir.'/table_definition.json';
		$path_xlsx = $this->exdb->conf()->path_definition_file;
		if( $this->exdb->fs()->is_newer_a_than_b( $path_xlsx, $path_json ) ){
			return false;
		}

		if(!is_file($path_json)){
			return false;
		}
		if(!is_readable($path_json)){
			return false;
		}
		$json = file_get_contents($path_json);
		$caches->table_definition = json_decode($json);
		return $caches;
	}
221795
def write_json(filename, content):
    '''
    
    '''

    j = _dumps(content, indent=4, sort_keys=True)
    if j:
        return write_file(filename, j)
184256
def _get_cached_response(self):
        """"""

        if not self._is_cached():
            response = self._download_response()
            self.cache.set_xml(self._get_cache_key(), response)

        return self.cache.get_xml(self._get_cache_key())
290074
@Override
    protected T readCacheDataFromFile(File file) throws CacheLoadingException {
        try {
            String resultJson = null;
            synchronized (file.getAbsolutePath().intern()) {
                resultJson = FileUtils.readFileToString(file, CharEncoding.UTF_8);
            }
            if (!StringUtils.isEmpty(resultJson)) {
                T result = deserializeData(resultJson);
                return result;
            }
            throw new CacheLoadingException("Unable to restore cache content : cache file is empty");
        } catch (FileNotFoundException e) {
            // Should not occur (we test before if file exists)
            // Do not throw, file is not cached
            Ln.w("file " + file.getAbsolutePath() + " does not exists", e);
            return null;
        } catch (CacheLoadingException e) {
            throw e;
        } catch (Exception e) {
            throw new CacheLoadingException(e);
        }
    }
173664
def load_json(filename):
    """"""
    try:
        if PY2:
            args = 'rb'
        else:
            args = 'r'
        with open(filename, args) as fid:
            data = json.load(fid)
        return data, None
    except Exception as err:
        return None, str(err)
943521
def load_json(filename, gzip_mode=False):
    ''''''

    open_file = open
    if gzip_mode:
        open_file = gzip.open

    try:
        with open_file(filename, 'rt') as fh:
            data = json.load(fh)
            data = convert_unicode_2_utf8(data)
            return data
    except AttributeError:
        # Python-2.6
        fh = open_file(filename, 'rt')
        data = json.load(fh)
        fh.close()
        data = convert_unicode_2_utf8(data)
        return data
1276548
def get_all_data_from_cache(self, filename=''):
        '''  '''

        data = ''
        if not filename:
            filename = self.cache_path_cache
        with open(filename, 'r') as cache:
            data = cache.read()
        return json.loads(data)
1115344
def get(self, key):
        """"""
        query = self._conn.execute("SELECT * FROM cache WHERE key=?", (key,))
        rec = query.fetchone()
        if rec is None:
            return None
        rec = dict(zip(self._columns, rec))

        if self.check_last_modified:
            if rec['modified'] is None:
                return None  # no last modified header present, so redownload

            head_resp = requests.head(key)
            new_lm = head_resp.headers.get('last-modified', None)
            if rec['modified'] != new_lm:
                return None

        resp = requests.Response()
        resp._content = rec['data']
        resp.status_code = rec['status']
        resp.encoding = rec['encoding']
        resp.headers = json.loads(rec['headers'])
        resp.url = key
        return resp
711929
function readKeys(force) {
    if (!force && options.cacheKeys) {
      return Promise.resolve(cachedKeys);
    }
    if (!force && options.cacheValues) {
      return Promise.resolve(Object.keys(cachedData));
    }

    return readdir(file).then(function(files) {
      var keys = [];

      files.forEach(function(filename) {
        if (filename.endsWith('.json')) {
          keys.push(filename.replace(/\.json$/, ''));
        }
      });

      return Promise.resolve(keys);
    });
  }
590910
def _get_json(location):
    """"""
    location = os.path.expanduser(location)
    try:
        if os.path.isfile(location):
            with io.open(location, encoding="utf-8") as json_data:
                return json.load(json_data, object_pairs_hook=OrderedDict).get("tests")
        elif "http" in location:
            json_data = requests.get(location)
            if not json_data:
                raise Dump2PolarionException("Failed to download")
            return json.loads(json_data.text, object_pairs_hook=OrderedDict).get("tests")
        else:
            raise Dump2PolarionException("Invalid location")
    except Exception as err:
        raise Dump2PolarionException("Failed to parse JSON from {}: {}".format(location, err))
1172814
def getJson(cls, url, method='GET', headers={}, data=None, socket=None, timeout=120):
        
        if not 'Content-Type' in headers:
            headers['Content-Type'] = ['application/json']

        body = yield cls().getBody(url, method, headers, data, socket, timeout)

        defer.returnValue(json.loads(body))
65582
def json(self):
        '''  '''
        if 'application/json' in self.environ.get('CONTENT_TYPE', '') \
        and 0 < self.content_length < self.MEMFILE_MAX:
            return json_loads(self.body.read(self.MEMFILE_MAX))
        return None
1009941
function (src, dest, content, fileObject) {
						var files = {};

						_.each(content, function (v, k) {
							var file = fileObject.orig.dest + '/' + k + '.json';

							files[file] = JSON.stringify(v);
						});

						return files;
					}