This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author sparverius
Recipients sparverius
Date 2020-02-19.06:23:22
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1582093402.26.0.349380477656.issue39686@roundup.psfhosted.org>
In-reply-to
Content
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": []}}'
History
Date User Action Args
2020-02-19 06:23:22sparveriussetrecipients: + sparverius
2020-02-19 06:23:22sparveriussetmessageid: <1582093402.26.0.349380477656.issue39686@roundup.psfhosted.org>
2020-02-19 06:23:22sparveriuslinkissue39686 messages
2020-02-19 06:23:22sparveriuscreate