Skip to main content

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))

Metadata

Release files for astjson 0.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for astjson 0.0.1
File Size Uploaded
astjson-0.0.1.tar.gz 2.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for astjson 0.0.1
File Interpreter ABI Platform
astjson-0.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 5.3 kB

Release files / astjson-0.0.1.tar.gz

Download URL astjson-0.0.1.tar.gz
Size 2.3 kB
Tags Source
SHA-256 checksum
How to use checksums
7c82b57d1ace0d14de5a9124a4e67673e52bfca68e4d909ea3cf61ace6e055eb
BLAKE2b-256 checksum
How to use checksums
359c8ea546da4009a2816609394d6fb1279b29a1f7042d93fee40c118311830f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.6

Release files / astjson-0.0.1-py3-none-any.whl

Download URL astjson-0.0.1-py3-none-any.whl
Size 3.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b8f6bfdc9af2add11856ec3fdd826a7c1026f3946f4d8b7616a7deb6e4c32983
BLAKE2b-256 checksum
How to use checksums
0c3bd90e576fa190bde8bd9ba158aa1dfce595d9c999854a489d356e5a18dc73
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.6

Release history Release notifications | RSS feed

This release

0.0.1 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page