Beautify JSON string or file.

    Keyword arguments:
    :param filename: use its contents as json string instead of
    json_str param.
    :param json_str: json string to be beautified.
168107
def beautify(filename=None, json_str=None):
    
    if filename is not None:
        with open(filename) as json_file:
            json_str = json.load(json_file)

    return  json.dumps(json_str, indent=4, sort_keys=True)
15720
def pretty_json(obj):
    
    if isinstance(obj, string_types):
        try:
            obj = json.loads(obj)
        except ValueError:
            raise ClientException("`obj` is not a json string")
    json_str = json.dumps(obj, sort_keys=True, indent=2)
    print(highlight(json_str, JsonLexer(), TerminalFormatter()))
1317012
def pretty(self):
        '''
        
        '''
        return '{}:{} in {}.{}'.format(
            self.filename,
            self.line_number,
            self.module_name,
            self.function_name)
512368
def from_json_file(cls, file_name):
        
        with open(file_name) as json_data:
            config = json.load(json_data)

        return cls(config)
1372339
def cache_json(filename):
    
    def cache_decorator(cacheable_function):
        @wraps(cacheable_function)
        def cache_wrapper(*args, **kwargs):
            path = CACHE_DIRECTORY + filename
            check_create_folder(path)
            if os.path.exists(path):
                with open(path) as infile:
                    return json.load(infile)
            else:
                function_output = cacheable_function(*args, **kwargs)
                with open(path, 'w') as outfile:
                    json.dump(function_output, outfile)
                return function_output
        return cache_wrapper
    return cache_decorator
299604
function requireJSON5(filename) {
    if ( path.extname(filename) == '' ) filename += fs.existsSync(filename + '.json5') ? '.json5' : '.json';
    try {
        return JSON5.parse(stripBOM(fs.readFileSync(filename, 'utf8')));
    }
    catch(error) {
        error.message = filename + ": " + error.message;
        throw error;
    }
}
812278
def load_install_json(self, filename=None):
        
        if filename is None:
            filename = 'install.json'

        file_fqpn = os.path.join(self.app_path, filename)
        install_json = None
        if os.path.isfile(file_fqpn):
            try:
                with open(file_fqpn, 'r') as fh:
                    install_json = json.load(fh)
            except ValueError as e:
                self.handle_error('Failed to load "{}" file ({}).'.format(file_fqpn, e))
        else:
            self.handle_error('File "{}" could not be found.'.format(file_fqpn))
        return install_json
822083
def get_json(file_name='../dxf.json.template'):
    
    with open(file_name, 'r') as f:
        t = json.load(f)
    return t
1195340
static function parse_json_file($filename)
	{
		$json_str = file_get_contents($filename);
		if ($json_str === FALSE) {
			// FIXME: Use different exception ?
			throw new JsonException("Failed to read file: ".$filename);
		}

		return static::parse_json_string($json_str);
	}
354363
def run_json(self):
        
        checks = {}
        for file in self.files:
            try:
                results = self._check(file)
            except Error as e:
                checks[file] = {
                    "error": e.msg
                }
            else:
                checks[file] = {
                    "score": results.score,
                    "comments": results.comment_ratio >= results.COMMENT_MIN,
                    "diff": "<pre>{}</pre>".format("\n".join(self.html_diff(results.original, results.styled))),
                }

        json.dump(checks, sys.stdout, indent=4)
        print()
222008
def stylify_files(text):
    """"""
    for filename in text:
        text[filename] = stylify_code(text[filename])
    return text
865402
def write_json_file(argname, cmd, basename, filename):
    

    value = getattr(cmd.distribution, argname, None)

    if isinstance(value, dict):
        value = json.dumps(
            value, indent=4, sort_keys=True, separators=(',', ': '))

    cmd.write_or_delete_file(argname, filename, value, force=True)
1307202
def json_pretty_print(s):
    ''''''
    s = json.loads(s)
    return json.dumps(s,
                      sort_keys=True,
                      indent=4,
                      separators=(',', ': '))
1205056
def save_json(filename: str, config: Union[List, Dict]):
    
    try:
        data = json.dumps(config, sort_keys=True, indent=4)
        with open(filename, 'w', encoding='utf-8') as fdesc:
            fdesc.write(data)
            return True
    except TypeError as error:
        _LOGGER.exception('Failed to serialize to JSON: %s',
                          filename)
        raise PytradfriError(error)
    except OSError as error:
        _LOGGER.exception('Saving JSON file failed: %s',
                          filename)
        raise PytradfriError(error)
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
824140
function prettify(data) {
    let json = JSON.stringify(data);
    json = json.replace(/{/g, "{\n\n\t");
    json = json.replace(/,/g, ",\n\t");
    json = json.replace(/}/g, ",\n\n}");
    return json;
  }
87629
def beautify(string, *args, **kwargs):
	

	parser = Parser(args, kwargs)
	return parser.beautify(string)