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

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

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

Uploaded Python 3

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

Hashes for astjson-0.0.1.tar.gz
Algorithm Hash digest
SHA256 7c82b57d1ace0d14de5a9124a4e67673e52bfca68e4d909ea3cf61ace6e055eb
MD5 c1747faa073caf4f80e684df8706b570
BLAKE2b-256 359c8ea546da4009a2816609394d6fb1279b29a1f7042d93fee40c118311830f

See more details on using hashes here.

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

Hashes for astjson-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b8f6bfdc9af2add11856ec3fdd826a7c1026f3946f4d8b7616a7deb6e4c32983
MD5 1e5d7e1ea75065417f8d2e18e8a367a6
BLAKE2b-256 0c3bd90e576fa190bde8bd9ba158aa1dfce595d9c999854a489d356e5a18dc73

See more details on using hashes here.

Supported by

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