class JSONDecoder:

    def decode_json(self, js):
        posts = []
if 'posts' in js:
    for p in js['posts']:
        if 'user' in p:
            posts.append(Post(p['title'], user=self._decode_user(p['user'])))
if 'group' in p:
    posts.append(Post(p['title'], group=self._decode_group(p['group'])))
return posts

def _decode_user(self, js):
    return User(js['name'])

def _decode_group(self, js):
    return Group(js['name'])
How to correctly transform JSON into Python objects?