[Python] Json string
This solution may not be a perfect one due to that fact that json is not "as compact as possible". However, json is quite convineniet when it comes to web. \n\n
This solution may not be a perfect one due to that fact that json is not "**as compact as possible**". However, json is quite convineniet when it comes to web. \n```\nclass Codec:\n\n    def serialize(self, root: TreeNode) -> str:\n        """Encodes a tree to a single string.\n        """\n\t\t# Converts a TreeNode instance into a dict using instance.__dict__\n\t\t# Convert the dict into json string using json.dumps()\n        return json.dumps(root, default=lambda x: x.__dict__)\n\n    def deserialize(self, data: str) -> TreeNode:\n        """Decodes your encoded data to tree.\n        """\n\t\t# Convert json string into dict\n        data = json.loads(data)\n\t\t\n\t\t# Recursively convert dict into TreeNode\n        def _deserialize(data_dict):\n            if data_dict is None:\n                return None\n            return TreeNode(\n                val = data_dict[\'val\'],\n                left = _deserialize(data_dict[\'left\']),\n                right = _deserialize(data_dict[\'right\'])\n            )\n        return _deserialize(data)\n```
['Python']