Save contents of `json_tree` (dict) to json file at `destpath`.
16275
def write_tree_to_json_tree(destpath, json_tree):
    
    parent_dir, _ = os.path.split(destpath)
    if not os.path.exists(parent_dir):
        os.makedirs(parent_dir, exist_ok=True)
    with open(destpath, 'w', encoding='utf8') as json_file:
        json.dump(json_tree, json_file, indent=2, ensure_ascii=False)
1169348
def save_json(histogram: Union[HistogramBase, HistogramCollection], path: Optional[str] = None, **kwargs) -> str:
    
    # TODO: Implement multiple histograms in one file?
    data = histogram.to_dict()

    data["physt_version"] = CURRENT_VERSION
    if isinstance(histogram, HistogramBase):
        data["physt_compatible"] = COMPATIBLE_VERSION
    elif isinstance(histogram, HistogramCollection):
        data["physt_compatible"] = COLLECTION_COMPATIBLE_VERSION
    else:
        raise TypeError("Cannot save unknown type: {0}".format(type(histogram)))

    text = json.dumps(data, **kwargs)
    if path:
        with open(path, "w", encoding="utf-8") as f:
            f.write(text)
    return text
532133
def write_json(self, path, contents, message):
        
        log.debug(message.format(path=path))
        makedirs(os.path.dirname(path))
        with open(path, "w") as fh:
            json.dump(contents, fh, indent=2, sort_keys=True)
1260676
def save_json_dict(filename, json_dict):
	
	if isinstance(json_dict, dict):
		with open(filename, "w") as f:
			f.write(json.dumps(json_dict, indent=4))
	else:
		raise TypeError("json_dict was not a dictionay. couldn't save.")
508498
def _schema_to_json_file_object(self, schema_list, file_obj):
        
        json.dump(schema_list, file_obj, indent=2, sort_keys=True)
100474
def dump_json(json_info, json_file, overwrite=True):
    
    if overwrite:
        mode = "w"
    else:
        mode = "w+"

    try:
        with open(json_file, mode) as f:
            f.write(json.dumps(json_info))
    except BaseException as e:
        logging.error(e.message)
1143972
def savejson(filename, datadict):
    
    for key, value in datadict.items():
        if type(value) == np.ndarray:
            datadict[key] = value.tolist()
        if type(value) == dict:
            for key2, value2 in value.items():
                if type(value2) == np.ndarray:
                    datadict[key][key2] = value2.tolist()
    with open(filename, "w") as f:
        f.write(json.dumps(datadict, indent=4))
635680
def save_list(key, *values):
    
    return json.dumps({key: [_get_json(value) for value in values]})
1313865
def write_dict_to_file(file_path, obj):
    
    lines = []
    for key, value in obj.items():
        lines.append(key + ':' + repr(value) + '\n')

    with open(file_path, 'w+') as file:
        file.writelines(lines)

    return None
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
325000
def get_json_tree_path(self, *args, **kwargs):
        
        json_tree_path = os.path.join(self.TREES_DATA_DIR, self.RICECOOKER_JSON_TREE)
        return json_tree_path
1272570
def save_metadata_json(self, filename: str, structure: JsonExportable) -> None:
        """"""
        if self.compress_json:
            filename += '.json.xz'
        else:
            filename += '.json'
        save_structure_to_file(structure, filename)
        if isinstance(structure, (Post, StoryItem)):
            # log 'json ' message when saving Post or StoryItem
            self.context.log('json', end=' ', flush=True)
703812
def _save_metadata(self):
        
        with open(self.paths.metadata(), 'w') as metadata_fd:
            utils.json_dump(self.metadata, metadata_fd)
1127262
def write_json_to_file(path, data):
    
    with open(path, 'w', encoding='utf-8') as f:
        json.dump(data, f)
729741
def load_json_from_file(file_path):
    """"""
    try:
        with open(file_path) as f:
            json_data = json.load(f)
    except ValueError as e:
        raise ValueError('Given file {} is not a valid JSON file: {}'.format(file_path, e))
    else:
        return json_data
384379
def dump_json_file(json_data, pwd_dir_path, dump_file_name):
    
    class PythonObjectEncoder(json.JSONEncoder):
        def default(self, obj):
            try:
                return super().default(self, obj)
            except TypeError:
                return str(obj)

    logs_dir_path = os.path.join(pwd_dir_path, "logs")
    if not os.path.isdir(logs_dir_path):
        os.makedirs(logs_dir_path)

    dump_file_path = os.path.join(logs_dir_path, dump_file_name)

    try:
        with io.open(dump_file_path, 'w', encoding='utf-8') as outfile:
            if is_py2:
                outfile.write(
                    unicode(json.dumps(
                        json_data,
                        indent=4,
                        separators=(',', ':'),
                        ensure_ascii=False,
                        cls=PythonObjectEncoder
                    ))
                )
            else:
                json.dump(
                    json_data,
                    outfile,
                    indent=4,
                    separators=(',', ':'),
                    ensure_ascii=False,
                    cls=PythonObjectEncoder
                )

        msg = "dump file: {}".format(dump_file_path)
        logger.color_print(msg, "BLUE")

    except TypeError as ex:
        msg = "Failed to dump json file: {}\nReason: {}".format(dump_file_path, ex)
        logger.color_print(msg, "RED")
1373409
def save_metadata(self, file_path):
    
    data = self.metadata
    with open(file_path, 'w')  as out_file:
      json.dump(data, out_file)