|
import json |
|
|
|
|
|
def write_json_to_file(json_object, json_file, mode='w', encoding='utf-8'): |
|
with open(json_file, mode, encoding=encoding) as outfile: |
|
json.dump(json_object, outfile, indent=4, sort_keys=True, ensure_ascii=False) |
|
|
|
|
|
def get_file_contents(filename, encoding='utf-8'): |
|
with open(filename, encoding=encoding) as f: |
|
content = f.read() |
|
return content |
|
|
|
|
|
def read_json(filename, encoding='utf-8'): |
|
contents = get_file_contents(filename, encoding=encoding) |
|
return json.loads(contents) |
|
|
|
|
|
def get_file_contents_as_list(file_path, encoding='utf-8', ignore_blanks=True): |
|
contents = get_file_contents(file_path, encoding=encoding) |
|
lines = contents.split('\n') |
|
lines = [line for line in lines if line != ''] if ignore_blanks else lines |
|
return lines |