Dump JSON data to a file
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'))
72538
def write_json(json_obj, filename, mode="w", print_pretty=True):
    '''
    '''
    with open(filename, mode) as filey:
        if print_pretty:
            filey.writelines(
                json.dumps(
                    json_obj,
                    indent=4,
                    separators=(
                        ',',
                        ': ')))
        else:
            filey.writelines(json.dumps(json_obj))
    return filename
236213
def save_json(object, handle, indent=2):
    """"""
    obj_json = json.dumps(object, indent=indent, cls=NumpyJSONEncoder)
    handle.write(obj_json)
704512
def dump(obj, path, **kw):
    
    open_kw = {'mode': 'w'}
    if PY3:  # pragma: no cover
        open_kw['encoding'] = 'utf-8'

    # avoid indented lines ending with ", " on PY2
    if kw.get('indent') and kw.get('separators') is None:
        kw['separators'] = (',', ': ')

    with open(str(path), **open_kw) as fp:
        return json.dump(obj, fp, **kw)
221795
def write_json(filename, content):
    '''
    
    '''

    j = _dumps(content, indent=4, sort_keys=True)
    if j:
        return write_file(filename, j)
1253527
def dump(obj, fp, **kwargs):
    """"""
    kwargs['default'] = serialize
    return json.dump(obj, fp, **kwargs)
482305
def json_dumps(o):
    """"""
    return json.dumps(o, indent=4, sort_keys=True, ensure_ascii=True,
                      separators=(',', ': ')).encode('ascii')
1118554
def dump(obj, fp, **user_kwargs):
    
    return json.dump(obj, fp, **_encoder_kwargs(user_kwargs))
126621
def dump_json(testcase, json_file):
    
    logging.info("dump testcase to JSON format.")

    with io.open(json_file, 'w', encoding="utf-8") as outfile:
        my_json_str = json.dumps(testcase, ensure_ascii=ensure_ascii, indent=4)
        if isinstance(my_json_str, bytes):
            my_json_str = my_json_str.decode("utf-8")

        outfile.write(my_json_str)

    logging.info("Generate JSON testcase successfully: {}".format(json_file))
407162
def write(self, node, filehandle):
        """"""
        dictexporter = self.dictexporter or DictExporter()
        data = dictexporter.export(node)
        return json.dump(data, filehandle, **self.kwargs)
1216752
def write_json_to_file(json_data, filename="metadata"):
    
    logger_jsons.info("enter write_json_to_file")
    json_data = rm_empty_fields(json_data)
    # Use demjson to maintain unicode characters in output
    json_bin = demjson.encode(json_data, encoding='utf-8', compactly=False)
    # Write json to file
    try:
        open("{}.jsonld".format(filename), "wb").write(json_bin)
        logger_jsons.info("wrote data to json file")
    except FileNotFoundError as e:
        print("Error: Writing json to file: {}".format(filename))
        logger_jsons.debug("write_json_to_file: FileNotFound: {}, {}".format(filename, e))
    logger_jsons.info("exit write_json_to_file")
    return
51577
def write_json(filename, data):
    
    with open(filename, 'w') as file:
        json.dump(data, file, indent=4, sort_keys=True)
959103
def json_dump(obj,       # type: Any
              fp,        # type: IO[str]
              **kwargs   # type: Any
             ):  # type: (...) -> None
    
    if six.PY2:
        kwargs['encoding'] = 'utf-8'
    json.dump(convert_to_dict(obj), fp, **kwargs)
702418
def dump(self, file, sort_keys: bool = True, **kwargs) -> None:
        """"""
        json.dump(self.to_json(), file, sort_keys=sort_keys, **kwargs)
49813
def format_to_json(data):
    
    if sys.stdout.isatty():
        return json.dumps(data, indent=4, separators=(',', ': '))
    else:
        return json.dumps(data)
298388
def save_json(self, fname='servers.json'):
        '''
            
        '''
        rows = sorted(self.keys())
        with open(fname, 'wt') as fp:
            json.dump([self[k] for k in rows], fp, indent=1)
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