from collections import OrderedDict # required for maintaining order data import json class AppConfig: def __init__(self, configFile = False): self.configFile = False self.get = False if configFile: self.configFile = configFile self.configLoad() def configLoad(self): try: with open(self.configFile) as data: obj = json.load( data, object_pairs_hook = OrderedDict # maintaining order data ) self.get = obj return True except Exception: return False def configSave(self, obj = False): obj = obj or self.get try: with open(self.configFile, "w") as outfile: json.dump( obj, outfile, ensure_ascii = False, # Keep special characters indent = 4 ) return True except Exception: return False ''' content of *.json { "string": "ok", "bool": true, "object": { "int": 3, "float": 3.3 } } ''' ''' Application example ''' AppConfig = AppConfig() AppConfig.configFile = '/home/user/App/config.json' # absolute path to *.json AppConfig.configLoad() print AppConfig.get['string'] AppConfig.get['object']['int'] = 4 if AppConfig.configSave(): print 'New value has been saved'