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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file astjson-0.0.1.tar.gz.
File metadata
- Download URL: astjson-0.0.1.tar.gz
- Upload date:
- Size: 2.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7c82b57d1ace0d14de5a9124a4e67673e52bfca68e4d909ea3cf61ace6e055eb
|
|
| MD5 |
c1747faa073caf4f80e684df8706b570
|
|
| BLAKE2b-256 |
359c8ea546da4009a2816609394d6fb1279b29a1f7042d93fee40c118311830f
|
File details
Details for the file astjson-0.0.1-py3-none-any.whl.
File metadata
- Download URL: astjson-0.0.1-py3-none-any.whl
- Upload date:
- Size: 3.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b8f6bfdc9af2add11856ec3fdd826a7c1026f3946f4d8b7616a7deb6e4c32983
|
|
| MD5 |
1e5d7e1ea75065417f8d2e18e8a367a6
|
|
| BLAKE2b-256 |
0c3bd90e576fa190bde8bd9ba158aa1dfce595d9c999854a489d356e5a18dc73
|