Last active
May 31, 2022 01:12
-
-
Save dylanwh/c2c4d49ce51118b44b1cc2a158a2fcb4 to your computer and use it in GitHub Desktop.
Revisions
-
dylanwh revised this gist
May 31, 2022 . 1 changed file with 2 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -11,13 +11,12 @@ def __init__(self,name="json",val=None): my_list = list() object.__setattr__(self, '_gron__dict', my_dict) object.__setattr__(self, '_gron__list', my_list) def __str__(self): import json as _json return _json.dumps(self.__dict, default = lambda x: x.__json()) def __json(self): if len(self.__list): return self.__list else: -
dylanwh created this gist
May 31, 2022 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,54 @@ #!/usr/bin/env python3 class gron: def __init__(self,name="json",val=None): if isinstance(val, dict): my_dict = val else: my_dict = dict() if isinstance(val, list): my_list = val else: my_list = list() object.__setattr__(self, '_gron__dict', my_dict) object.__setattr__(self, '_gron__list', my_list) pass def __str__(self): import json as _json return _json.dumps(self.__dict, default = lambda x: x.__gron_json()) def __gron_json(self): if len(self.__list): return self.__list else: return self.__dict def __setitem__(self, item, val): if isinstance(item, int): l = self.__list while len(l) <= item: l.append(None) l[item] = val else: self.__dict[item] = valddk def __setattr__(self, key, val): if isinstance(val, (dict,list)): val = gron(key, val) self.__dict[key] = val return def __getattr__(self, key): if key in self.__dict: return self.__dict[key] else: self.__dict[key] = gron(key) return self.__dict[key] if __name__ == '__main__': import sys json = gron() for line in sys.stdin: exec(line, None, {"json": json}) print(json)