Skip to main content

Class project to convert files from CSV to JSON and vice-versa

Project description

Converts files from CSV to JSON formats and vice-versa.

This is meant to be used as the final project for the Python course from the Artificial Intelligence program at PUC Minas.

It has nothing groundbreaking, so you should safely ignore it. In any case, if you managed to get here, feel free to check my other (hopefully) more useful projects:

Installation

pip install file-converter-fgsm

This assumes you are inside a virtual environment. If you wish to install it globally on the system (which I do not recommend for this class project), add sudo at the beginning.

Usage

Once installed, a file_converter command becomes available.

Type

file_converter --help

to get further help.

Examples

Converting a single file

Suppose you have a file sample_file.csv in the current directory with the contents

header1,header2,header3
1,"a",1.5
2,"b",3.2

To convert it into a json format, run

file_converter --conversion=csv2json --input_path=./sample_file.csv

and then you should have a sample_file.json in the same directory with the contents:

[
    {
        "header1": 1,
        "header2": "\"a\"",
        "header3": 1.5
    },
    {
        "header1": 2,
        "header2": "\"b\"",
        "header3": 3.2
    }
]

Notice how the quotes have been escaped.

The previous command is short for

file_converter --conversion=csv2json --input_path=./sample_file.csv --output_path=. --separator=, --prefix=""

Experiment running again but with a different --output_path.

The command supports the other way for the conversion as well. To test that, let us convert the recently converted json file but prefixing the resulting file name with a new_:

file_converter --conversion=json2csv --input_path=./sample_file.json --prefix="new_"

Notice the csv2json became json2csv in the --conversion attribute. Also, we should have a new_sample_file.csv with the same contents of the first.

Converting all files in a folder

If instead of a single file path you pass a folder in the --input_path parameter, the command will attempt to convert all files inside of it. Notice they all should have the same separator.

Experiment passing the current directory like

file_converter --conversion=csv2json --input_path=. --prefix="from_folder_"

If you followed the previous example, you should have two new json files starting with from_folder_.

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

file-converter-fgsm-0.1.1.tar.gz (6.3 kB view details)

Uploaded Source

Built Distribution

file_converter_fgsm-0.1.1-py3-none-any.whl (7.7 kB view details)

Uploaded Python 3

File details

Details for the file file-converter-fgsm-0.1.1.tar.gz.

File metadata

  • Download URL: file-converter-fgsm-0.1.1.tar.gz
  • Upload date:
  • Size: 6.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.11 CPython/3.9.7 Linux/5.13.19-2-MANJARO

File hashes

Hashes for file-converter-fgsm-0.1.1.tar.gz
Algorithm Hash digest
SHA256 3a4a67cdcab5cc25023afb630ba2dc3ae281d49877844ac3a18055467b2d09f9
MD5 a1aa314d0b017cc90f3b212c4e1da049
BLAKE2b-256 e79b3234a8f0481b79886a63ebb9d5659eb7a13563968963ccab558170464516

See more details on using hashes here.

File details

Details for the file file_converter_fgsm-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: file_converter_fgsm-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 7.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.11 CPython/3.9.7 Linux/5.13.19-2-MANJARO

File hashes

Hashes for file_converter_fgsm-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 4f55d5fb9f38605b41df05964c52c4a26b8ca9077286b9410a59b5147a2539d7
MD5 ecf3524b9ac7a569061057aafd4d76d3
BLAKE2b-256 b660f1f001b21c337ca468928616ee16e189f051fa6abf957f28ef1606364b3a

See more details on using hashes here.

Supported by

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