Every line of 'open json file python' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.
20 def read_json(path): 21 return json.load(open(path))
18 def read_json_file(path): 19 """ 20 Reads and return the data from the json file at the given path. 21 22 Parameters: 23 path (str): Path to read 24 25 Returns: 26 dict,list: The read json as dict/list. 27 """ 28 29 with open(path, 'r', encoding='utf-8') as f: 30 data = json.load(f) 31 32 return data
17 def open_python_file(filename): 18 """Open a read-only Python file taking proper care of its encoding. 19 20 In Python 3, we would like all files to be opened with utf-8 encoding. 21 However, some author like to specify PEP263 headers in their source files 22 with their own encodings. In that case, we should respect the author's 23 encoding. 24 """ 25 import tokenize 26 27 if hasattr(tokenize, "open"): # Added in Python 3.2 28 # Open file respecting PEP263 encoding. If no encoding header is 29 # found, opens as utf-8. 30 return tokenize.open(filename) 31 else: 32 return open(filename, "r")
104 def _read_json(path_to_json): 105 with open(path_to_json) as f: 106 return json.load(f)