@@ -0,0 +1,2222 @@
+import json%0A%0Ar%22%22%22Dict and Json parsing mixin.%0A%0AFor example::%0A%0A    class Human(JsonMixin):%0A        def __init__(self, id, name, favorite):%0A            self.id = id%0A            self.name = name%0A            self.favorite = Food.from_dicts(favorite)%0A%0A%0A    class Food(JsonMixin):%0A        def __init__(self, id, name, color=None):%0A            self.id = id%0A            self.name = name%0A            if color:%0A                self.color = color%0A%0A    j = '''%0A    %7B%0A        %22id%22: 10,%0A        %22name%22: %22tadashi%22,%0A        %22favorite%22: %5B%0A            %7B%22id%22: 1, %22name%22: %22apple%22%7D,%0A            %7B%22id%22: 2, %22name%22: %22orange%22, %22color%22: %22white%22%7D%0A        %5D%0A    %7D%0A    '''%0A%0A    d = %7B%0A        %22id%22: 10,%0A        %22name%22: %22tadashi%22,%0A        %22favorite%22: %5B%0A            %7B%22id%22: 1, %22name%22: %22apple%22%7D,%0A            %7B%22id%22: 2, %22name%22: %22orange%22, %22color%22: %22white%22%7D%0A        %5D%0A    %7D%0A%0A    %3E%3E%3E y1 = Human.from_json(j)%0A    %3E%3E%3E y2 = Human.from_dict(d)%0A    %3E%3E%3E y1.to_json() == y2.to_json()%0A    True%0A%22%22%22%0A%0A__version__ = '0.1.0'%0A__all__ = %5B'JsonMixin'%5D%0A__author__ = 'Tadashi Aikawa %3Csyou.maman@gmail.com%3E'%0A%0A%0Aclass DictMixin(object):%0A    @classmethod%0A    def from_dict(cls, d):%0A        return cls(**d)%0A%0A    @classmethod%0A    def from_dicts(cls, ds):%0A        return %5Bcls(**d) for d in ds%5D%0A%0A    def to_dict(self):%0A        return self._traverse_dict(self.__dict__)%0A%0A    def _traverse_dict(self, instance_dict):%0A        output = %7B%7D%0A        for key, value in instance_dict.items():%0A            output%5Bkey%5D = self._traverse(key, value)%0A        return output%0A%0A    def _traverse(self, key, value):%0A        if isinstance(value, DictMixin):%0A            return value.to_dict()%0A        elif isinstance(value, dict):%0A            return self._traverse_dict(value)%0A        elif isinstance(value, list):%0A            return %5Bself._traverse(key, i) for i in value%5D%0A        elif hasattr(value, '__dict__'):%0A            return self._traverse_dict(value.__dict__)%0A        else:%0A            return value%0A%0A%0Aclass JsonMixin(DictMixin):%0A    @classmethod%0A    def from_json(cls, data):%0A        return cls.from_dict(json.loads(data))%0A%0A    def to_json(self, indent=0):%0A        return json.dumps(self.to_dict(), indent=indent, ensure_ascii=False)%0A%0A    def to_pretty_json(self):%0A        return self.to_json(4)%0A

Add json mixin