Giter Site home page Giter Site logo

krabeeputh / csv-to-json Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 1.0 6 KB

Cvs2Json, a Python class to convert text or CSV (Comma Separated Values) to JSON (JavaScript Object Notation) format for Django model

Python 100.00%
django python-3 jsonformat csv-files

csv-to-json's Introduction

CSV-to-JSON

Cvs2Json, a Python class to convert text or CSV (Comma Separated Values) to JSON (JavaScript Object Notation) format for Django model

Introduction

This is my first program. It is a class module to help you to convert text or CSV to JSON format for Django model which need three properties: “pk”, “model” and “fields”. See serialization formats from Djgno more information.

Instead of using strip() and split() functions as the tutorials from https://www.geeksforgeeks.org/convert-text-file-to-json-in-python/ and https://github.com/jcamier/csv-json-django/blob/master/convert_csv_to_json.py. I use Python's built-in csv library. It is more easier, convenient and powerful. It was born to to read and write tabular data in CSV format which was generated by Microsoft Excel.

I developed this program to support Thai language with utf8 encoding (UNICODE) so I hope it will support any language too.

How to use it?

1. Import module
2. Config some variables

  • The CSV file to be converted
  • The JSON output file
  • App and Model name
  • List of fields in your model

3. Crate object to use
see more detail in file test.py

Input & Output

I have more 2 files

  • countries.csv, It's a source file to be converted to JSON format. You can use it for testing the program.
  • countries.json, This file auto generate from class. It's my JSON output file. You can run my program to get the same output format

csv-to-json's People

Contributors

krabeeputh avatar

Stargazers

 avatar

Watchers

 avatar

Forkers

5l1v3r1

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.