First, read the file normally
with open('test.json', 'r') as f:
js=f.read()
When instructed to load as json
import json
nb=json.loads(js)
Easy to handle as a dictionary format! It can be used to store external parameters
print(nb)
#[Out]#{'color_scheme': 'Packages/User/Tubnil_kai (SL) (SublimePythonIDE).tmTheme', 'enable_tab_scrolling': True, 'detect_slow_plugins': False, 'always_show_minimap_viewport': True, 'draw_white_space': 'all', 'draw_minimap_border': True, 'file_exclude_patterns': ['*.exe', '*.zip', '*.lnk', '*.db', '*.pptm', '*.docx', '*.pdf', '*.dwt', '*.bak', '*.xlsx', '*.ex4', '*.ex4old']}
print(nb['color_scheme'])
#[Out]#Packages/User/Tubnil_kai (SL) (SublimePythonIDE).tmTheme
print("*.exe" in nb['file_exclude_patterns'])
#[Out]#True
It seems that you can read directly from the file if it is json.load ()
instead of json.loads ()
Can be shortened!
import json
with open('test.json', 'r') as f:
nb=json.load(f)
print(nb)
Recommended Posts