Save a dictionary in a JSON file within the cache directory.
343447
def save(self, name, data, location='local', kind='json'):
        """"""
        file_ext = '.json' if kind == 'json' else '.pkl'
        path = self._get_path(name, location, file_ext=file_ext)
        _ensure_dir_exists(op.dirname(path))
        logger.debug("Save data to `%s`.", path)
        if kind == 'json':
            _save_json(path, data)
        else:
            _save_pickle(path, data)
597852
public function loadCacheDetails()
    {
        $cacheFile = md5($this->url);
        $this->fileName = $this->saveFolder . $cacheFile;
        $this->fileJson = $this->fileName . ".json";
        if (is_readable($this->fileJson)) {
            $this->cache = json_decode(file_get_contents($this->fileJson), true);
        }
    }
903888
def load_dictionary(filename):
    """"""
    filename = osp.abspath(filename)
    old_cwd = getcwd()
    tmp_folder = tempfile.mkdtemp()
    os.chdir(tmp_folder)
    data = None
    error_message = None
    try:
        with tarfile.open(filename, "r") as tar:
            tar.extractall()
        pickle_filename = glob.glob('*.pickle')[0]
        # 'New' format (Spyder >=2.2 for Python 2 and Python 3)
        with open(pickle_filename, 'rb') as fdesc:
            data = pickle.loads(fdesc.read())
        saved_arrays = {}
        if load_array is not None:
            # Loading numpy arrays saved with np.save
            try:
                saved_arrays = data.pop('__saved_arrays__')
                for (name, index), fname in list(saved_arrays.items()):
                    arr = np.load( osp.join(tmp_folder, fname) )
                    if index is None:
                        data[name] = arr
                    elif isinstance(data[name], dict):
                        data[name][index] = arr
                    else:
                        data[name].insert(index, arr)
            except KeyError:
                pass
    # Except AttributeError from e.g. trying to load function no longer present
    except (AttributeError, EOFError, ValueError) as error:
        error_message = to_text_string(error)
    # To ensure working dir gets changed back and temp dir wiped no matter what
    finally:
        os.chdir(old_cwd)
        try:
            shutil.rmtree(tmp_folder)
        except OSError as error:
            error_message = to_text_string(error)
    return data, error_message
644945
def _write_cache_to_file(self):
        """"""
        with(open(self._cache_file_name, 'w')) as fp:
            fp.write(simplejson.dumps(self._cache))
139780
def write(self):
        
        io.debug("Storing cache '{0}'".format(self.path))
        with open(self.path, "w") as file:
            json.dump(self._data, file, sort_keys=True, indent=2,
                      separators=(',', ': '))
1125055
def save_local_metadata(self):
        
        # save to the set local path and add .json
        with open(self.filepath + '.json', 'w+') as outfile:
            json.dump(self._prep_metadata(), outfile, indent=4)
1365134
def save(self, cachedir=None, cfgstr=None, verbose=VERBOSE, quiet=QUIET,
             ignore_keys=None):
        
        fpath = self.get_fpath(cachedir, cfgstr=cfgstr)
        if verbose:
            print('[Cachable] cache save: %r' % (basename(fpath),))

        if hasattr(self, '__getstate__'):
            statedict = self.__getstate__()
        else:
            statedict = self.__dict__

        if ignore_keys is None:
            save_dict = statedict
        else:
            save_dict = {key: val
                         for (key, val) in six.iteritems(statedict)
                         if key not in ignore_keys}

        util_io.save_data(fpath, save_dict)
        return fpath
501582
def json_to_file(data, filename, pretty=False):
    ''''''
    kwargs = dict(indent=4) if pretty else {}
    dirname = os.path.dirname(filename)
    if not os.path.exists(dirname):
        os.makedirs(dirname)
    dump = json.dumps(api.__schema__, **kwargs)
    with open(filename, 'wb') as f:
        f.write(dump.encode('utf-8'))
84437
def addJsonDirectory(self, directory, test=None):
    """"""

    for filename in os.listdir(directory):
      try:
        fullPath = os.path.join(directory, filename)
        if not test or test(filename, fullPath):
          with open(fullPath) as f:
            jsonData = json.load(f)
            name, _ = os.path.splitext(filename)
            self.addSource(name, jsonData)

      except ValueError:
        continue
174714
def download_json(local_filename, url, clobber=False):
    """"""
    with open(local_filename, 'w') as json_file:
        json_file.write(json.dumps(requests.get(url).json(), sort_keys=True, indent=2, separators=(',', ': ')))
236213
def save_json(object, handle, indent=2):
    """"""
    obj_json = json.dumps(object, indent=indent, cls=NumpyJSONEncoder)
    handle.write(obj_json)
289105
def retrieve(self, key):
        """"""
        column_file = os.path.join(self._hash_dir, '%s.json' % key)
        cache_file = os.path.join(self._hash_dir, '%s.npy' % key)

        if os.path.exists(cache_file):
            data = np.load(cache_file)
            if os.path.exists(column_file):
                with open(column_file, 'r') as json_file:
                    columns = json.load(json_file)
                data = pd.DataFrame(data, columns=columns)
        else:
            return None

        return data
353281
function Persist(cacheFile, keys, log) {
  var pdata = (cacheFile) ? JSON.parse(fs.readFileSync(cacheFile, 'utf8')) : {}
    , guid = makeGuid(keys);

  pdata[guid] = pdata[guid] || {};

  // this is the only member that needs access to the full object and the file
  this.save = function () {
    if (cacheFile) {
      fs.writeFileSync(cacheFile, JSON.stringify(pdata));
    }
  };

  // members need only know their config object
  this.cfg = pdata[guid];
  this.cfg.opts = this.cfg.opts || {};

  // was a logger passed down?
  this.log = (type.isFunction(log)) ? log : noop;
}
38992
def load_json(file):
    """"""
    here = os.path.dirname(os.path.abspath(__file__))
    with open(os.path.join(here, file)) as jfile:
        data = json.load(jfile)
    return data
91293
def _save_json(self, filename):
        """"""
        with open(filename, 'w') as file_handle:
            json.dump(self._sensors, file_handle, cls=MySensorsJSONEncoder,
                      indent=4)
            file_handle.flush()
            os.fsync(file_handle.fileno())
812431
def write_dicts_to_json(self, data):
        
        with open(self.path, "w") as out:
            json.dump(
                data,  # data
                out,  # file handler
                indent=4, sort_keys=True  # pretty print
            )
1029465
def save_json(self, frames):
        
        if self.json_save_path is None: return
        path = os.path.join(self.json_save_path, '%s.json' % self.id)
        if not os.path.isdir(self.json_save_path):
            os.mkdir(self.json_save_path)
        with open(path, 'w') as f:
            json.dump(frames, f)
        self.json_data = frames