Skip to main content

A tool to convert directory contents to JSON

Project description

DTJ (Directory to JSON)

Overview

DTJ (Directory to JSON) is a Python command-line tool, particularly useful for quickly generating and sharing representations of directory structures in a token-efficient manner, making it ideal for interactions with language models like ChatGPT.

Example output

dtj foo
[
    {
        "filename": "main.py",
        "content": "# Main application file\nimport app\n\napp.run()"
    },
    {
        "filename": "app.py",
        "content": "# App module\n\ndef run():\n    print('Running the app')"
    },
    {
        "filename": "utils.py",
        "content": "# Utility functions\n\ndef helper():\n    return 'Helper function'"
    }
]

Features

  • Convert directory contents to JSON format.
  • Include or exclude specific file types.
  • Recursive directory parsing.
  • Options for output: printing to console, saving to a file, or copying to the clipboard.

Installation

To use DTJ, you'll need Python installed on your system. Clone this repository or download the DTJ.py script.

git clone https://github.com/adriangalilea/dtj.git
cd DTJ

Usage

Run DTJ from the command line with the following options:

python dtj.py <target-directory> [options]

Options:

  • -i or --include: Specify file extensions to include (e.g., py, html).
  • -e or --exclude: Specify file extensions to exclude.
  • -o or --output-file: Set the output JSON file name.
  • -r or --recursive: Enable recursive search in directories.
  • -p or --print: Print the output using rich formatting.
  • -c or --clipboard: Copy the output to the clipboard.

Example

python DTJ.py myfolder -i py html -o output.json -r

This command will parse all .py and .html files in myfolder recursively and save the JSON output to output.json.

Authors

  • Adrian Galilea - Initial work

Acknowledgments

  • Hat tip to ChatGPT for assistance with project setup and documentation.

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

dtj-0.1.0.tar.gz (3.2 kB view hashes)

Uploaded Source

Built Distribution

dtj-0.1.0-py3-none-any.whl (3.5 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