return {attr: value for attr, value in non_methods if not attr.startswith('__')
    }
if __name__ == '__main__':
    tree = TreeNode(42, TreeNode(24), TreeNode(242))
print(ObjectJSONEncoder().encode(tree))
Easy JSON encoding with Python