Skip to content

Instantly share code, notes, and snippets.

@gothma
Created February 12, 2015 13:39
Show Gist options
  • Save gothma/353a803fe4bdeda66912 to your computer and use it in GitHub Desktop.
Save gothma/353a803fe4bdeda66912 to your computer and use it in GitHub Desktop.
Import json as native python class
#!/usr/bin/env python3
import json
class JSONConfig:
def __init__(self, dictionary):
for k, v in dictionary.items():
if type(v) is dict:
setattr(self, k, JSONConfig(v))
else:
setattr(self, k, v)
def __repr__(self):
return str(self.__dict__)
@staticmethod
def load(fp):
with open(fp) as json_file:
dictionary = json.load(json_file)
return JSONConfig(dictionary)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment