New submission from Richard K <qpot...@gmail.com>:
Currently within the ast module, `dump` generates a string representation of the AST for example, >>> ast.dump(node) 'Module(body=[], type_ignores=[])' The proposed enhancement would provide a complementary function, `dump_json` as in a json representation of the ast. This would be useful for those who would like to benefit from the utilities of the json module for formatting, pretty-printing, and the like. It would also be useful for those who want to serialize the AST or export it in a form that can be consumed in an other programming language. A simplified example, >>> import ast >>> node = ast.parse('') >>> ast.dump_json(node) {'Module': {'body': [], 'type_ignores': []}} A simplified example of using `ast.dump_json` with the json module, >>> import json >>> json.dumps(ast.dump_json(node)) '{"Module": {"body": [], "type_ignores": []}}' ---------- components: Library (Lib) messages: 362256 nosy: sparverius priority: normal severity: normal status: open title: add dump_json to ast module type: enhancement versions: Python 3.9 _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue39686> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com