Skip to main content

Easily convert your CSV to custom JSON

Project description

csv-to-custom-json-python

How to install

python3 -m pip install csv-to-custom-json

Tests && coverage

Coverage is 100%

# install
python -m pip install coverage unittest

# only test
python -m unittest

# coverage
coverage run -m unittest  && coverage report -m

How to use csv-to-custom-json

Classic usage

Just import the function and use it !

from csv_to_custom_json import parseFile

result = parseFile("myfile.csv")

How to use the schema

Create a schema variable and put it as second parameter !

Exemple with a simple csv :

num1,num2,num3
1,2,3
4,5,6
7,8,9
from csv_to_custom_json import parseFile

def callback(value):
    return None

schema = {
    "num1": "string",
    "num2": callback,
    "num3": "int"
}

result = parseFile("myfile.csv", schema)

Caption :

  • ad you can see the schema can contains function, or string with the type
  • the values with type will be parsed
  • attribute of the object are the word in the first line of the csv

More complexe schema

It's the same as a simple schema :

from csv_to_custom_json import parseFile

schema = {
    "obj1": {
        "obj2": {
            "num4": "string"
        }
    },
    "num2": "",
    "num3": ""
}
result = parseFile("myfile.csv", schema)

If you want to check some real case, check out the folder test in the GitHub repository

If you want to see and use options check that documentation: How-to-options

See also

License

Licensed under the MIT License - LICENSE

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

csv-to-custom-json-0.0.4.tar.gz (9.0 kB view details)

Uploaded Source

Built Distribution

csv_to_custom_json-0.0.4-py3-none-any.whl (6.1 kB view details)

Uploaded Python 3

File details

Details for the file csv-to-custom-json-0.0.4.tar.gz.

File metadata

  • Download URL: csv-to-custom-json-0.0.4.tar.gz
  • Upload date:
  • Size: 9.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.12

File hashes

Hashes for csv-to-custom-json-0.0.4.tar.gz
Algorithm Hash digest
SHA256 9f56e7b164cd2da01b5d33a16fe7d79fd7ff0fcc14fcc6961dd5d9f1c4adc94a
MD5 8e08e27e02c1a1799e5ec2cac1aa4de4
BLAKE2b-256 3617a973f8e9044602f54934a0dac331883b2af91387a871983e9b1757cf56bb

See more details on using hashes here.

File details

Details for the file csv_to_custom_json-0.0.4-py3-none-any.whl.

File metadata

File hashes

Hashes for csv_to_custom_json-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 5bba2252e1ea2f6d0e8c4b5fac869951bc6afefdfc7b91af7546cdf471b0c253
MD5 383f728808a4980b1c929fcd60a3bcf6
BLAKE2b-256 9634a912213e4231f2b50e08e230e333104dc22b9990232e3ca4acc44dec1f43

See more details on using hashes here.

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