This project provides a simple C program that converts CSV data to JSON and makes an optional HTTPS POST request to a specified API endpoint. Additionally, the project includes a test suite to verify the functionality of the CSV to JSON conversion
This project is currently a non-production, experimental endeavor. While functional, it may not yet meet the standards required for production use. It was developed as an intellectual exercise to enhance and refresh my skills and familiarity with the C programming language and associated developer tooling.
csvToJson/
├── bin/
│ ├── csvToJSON
│ └── test_csvToJSON
├── data/
│ └── test.csv
├── src/
│ ├── csvToJSON.c
│ ├── csvToJSON.h
│ ├── csvToJSON_lib.c
│ └── test_csvToJSON.c
├── .vscode/
│ └── settings.json
├── .clang-format
├── .editorconfig
├── .gitignore
├── CONTRIBUTING.md
├── configure
├── LICENSE
├── Makefile
└── README.md
- bin/: Directory containing the compiled binaries.
- data/: Directory containing test CSV files.
- src/: Directory containing the source code files.
- csvToJSON.c: Contains the
main
function and the HTTPS POST request logic. - csvToJSON.h: Header file with function declarations.
- csvToJSON_lib.c: Contains the CSV to JSON conversion logic.
- test_csvToJSON.c: Test program for the CSV to JSON conversion.
- csvToJSON.c: Contains the
- vscode/: Directory containing VSCode settings.
- settings.json: VSCode settings for consistent code formatting.
- .clang-format: ClangFormat configuration for code style enforcement.
- .editorconfig: EditorConfig file for consistent coding styles across different editors.
- .gitignore: File specifying which files and directories to ignore in version control.
- CONTRIBUTING.md: Guidelines for contributing to the project.
- configure: Script to generate the Makefile.
- LICENSE: License file containing the MIT license text.
- Makefile: Build configuration for the project using GNU Make.
- CMakeLists.txt: Alternative / OPTIONAL build config for the project.
- README.md: File providing information about the project. (This file!)
- GCC (GNU Compiler Collection)
- libcurl development libraries
This project is designed for Unix-like operating systems such GNU/Linux, MacOS, BSD.
For non-Unix-like operating systems such as Windows, you may need to use compatibility layers or tools such as Cygwin or WSL (Windows Subsystem for Linux) to compile and run the project.
Build the project using GNU Make:
-
Make the
configure
script executable:chmod +x configure
-
Run the
configure
script to generate the Makefile:./configure
-
Build the project and the tests:
make
Optionally, you may build the project using CMake:
-
Build the project:
cmake CMakeLists.txt
Usage:
./csvToJSON <csv_file_path> [<api_endpoint>] [<bearer_token>]
To convert a CSV file to JSON
./csvToJSON <csv_file_path>
To convert a CSV file to JSON and send the JSON to a public endpoint on a server via HTTPS:
./csvToJSON ../data/test.csv https://api.example.com/endpoint
To convert a CSV file to JSON and send the JSON to an endpoint requiring Authentication:
./csvToJSON ../data/test.csv https://api.example.com/endpoint your_bearer_token
To run the tests, use the following command:
make test
This will compile and execute the test program test_csvToJSON
, verifying the CSV to JSON conversion.
test.csv
:
firstName,lastName,dob
John,Doe,1985-08-01
Jane,Doe,1991-04-20
For the provided test.csv
, the expected JSON output is:
[{"firstName":"John","lastName":"Doe","dob":"1985-08-01"},{"firstName":"Jane","lastName":"Doe","dob":"1991-04-20"}]
This project is licensed under the MIT License.
Feel free to submit issues or pull requests if you find any bugs or want to add new features.
Sure! Here's an improved version of the TODO section:
Refactor the project to adhere more closely to the UNIX philosophy by separating concerns. Specifically, remove the HTTP API request functionality from this tool. Instead, create a standalone tool dedicated to making HTTP requests. The JSON output from this tool can be piped to the HTTP request tool, allowing for greater modularity and flexibility.
-
Create a Separate HTTP Request Tool:
- Develop a standalone tool that handles HTTP requests.
- Use CLI flags or parameters to specify the hostname and authentication details.
-
Leverage Existing Tools:
- Alternatively, use existing standardized tools such as
cURL
to handle HTTP requests.
- Alternatively, use existing standardized tools such as
-
Example Usage:
- Pipe the JSON output from this tool to the HTTP request tool.
- Example:
./csvToJSON file.csv | ./httpRequester --hostname example.com --auth "Bearer token"
- Or using
cURL
directly:./csvToJSON file.csv | curl -X POST -H "Content-Type: application/json" -H "Authorization: Bearer token" -d @- https://api.example.com
By modularizing the functionality, we can create more reusable and maintainable components that align with the UNIX philosophy of building simple, single-purpose tools that work together to become capable of performing complex tasks.