Skip to main content

Easily convert your CSV to custom JSON

Project description

csv-to-custom-json-python pypi version pypi downloads

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 !

Example 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-1.0.0.tar.gz (9.0 kB view details)

Uploaded Source

Built Distribution

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

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

Uploaded Python 3

File details

Details for the file csv_to_custom_json-1.0.0.tar.gz.

File metadata

  • Download URL: csv_to_custom_json-1.0.0.tar.gz
  • Upload date:
  • Size: 9.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.10.12

File hashes

Hashes for csv_to_custom_json-1.0.0.tar.gz
Algorithm Hash digest
SHA256 c5ce05249329453f11fb406984a033b915eb41681e4694de411c4420c9311f4e
MD5 660e7372aca47e45c4ca0dbdfe39836a
BLAKE2b-256 7d8fc32632498dcc670dc1788e15b9e0b57418f0c5126b172cf486d03d4198f4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for csv_to_custom_json-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ed911d49709159cc8838075ef0d573ee3901319c2b61467091d99a26fdcf8cdb
MD5 4d1d8d209ca78ae4989b7124bc205a4a
BLAKE2b-256 16e4549907b211dad94f98f796e52aef7f71fe457f766e954a82223bae4e51ba

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