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

Uploaded Source

Built Distribution

csv_to_custom_json-0.0.4-py3-none-any.whl (6.1 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