Skip to main content

AST to JSON converter

Project description

AST to JSON Converter

This Python module provides a utility function ast_to_json which takes a Python Abstract Syntax Tree (AST) and converts it to a dictionary. The dictionary can be serialized to JSON. This is useful for scenarios where you need to analyze or manipulate the Python Abstract Syntax tree in a programming language other than Python. I tried to make the implementation similar to ast.dump to preserve the structure of the abstract syntax trees.

Installation

To install this module, simply clone the repository and import the function into your Python script:

import ast
from typing import Any, Dict
import json
import astjson

with open("your_python_program.py") as f:
    program = f.read()
t = ast.parse(program)
print(json.dumps(astjson.ast_to_json(t), indent=2))

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

astjson-0.0.1.tar.gz (2.3 kB view hashes)

Uploaded Source

Built Distribution

astjson-0.0.1-py3-none-any.whl (3.1 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page