https://github.com/scblur869/csv-2-json
an API written in Go that reads a CSV file and sends a json response
https://github.com/scblur869/csv-2-json
api csv gin-gonic golang
Last synced: 12 months ago
JSON representation
an API written in Go that reads a CSV file and sends a json response
- Host: GitHub
- URL: https://github.com/scblur869/csv-2-json
- Owner: scblur869
- Created: 2021-03-22T20:32:27.000Z (about 5 years ago)
- Default Branch: main
- Last Pushed: 2021-06-17T17:24:48.000Z (almost 5 years ago)
- Last Synced: 2025-02-06T20:39:35.111Z (about 1 year ago)
- Topics: api, csv, gin-gonic, golang
- Language: Go
- Homepage:
- Size: 2.49 MB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# CSV 2 JSON
## This is just a simple API written in GO that reads a standard CSV file with the first row as a the header
### once read, an http json response is sent back to the client with the CSV data in json format. One of the beauties of Go is the use map[string]interface{} or just the ability to use an empty interface for arbitrary data
you can just hold everything in a simple struct
```go
type CSVData struct {
Header []string `json:"header"`
Rows []map[string]interface{} `json:"data"`
}
```
Single Endpoint
```bash
POST /api/v1/upload
multipart/form-data;
```
### example
### CSV File
```console
"Code","Name","Category","Quantity"
"f230fh0g3","Bamboo Watch","Accessories","24"
"nvklal433","Black Watch","Accessories","61"
"zz21cz3c1","Blue Band","Fitness","2"
"244wgerg2","Blue T-Shirt","Clothing","25"
"h456wer53","Bracelet","Accessories","73"
"av2231fwg","Brown Purse","Accessories","0"
"bib36pfvm","Chakra Bracelet","Accessories","5"
"mbvjkgip5","Galaxy Earrings","Accessories","23"
"vbb124btr","Game Controller","Electronics","2"
"cm230f032","Gaming Set","Electronics","63"
```
### JSON response
```json
{
"header": [
"Code",
"Name",
"Category",
"Quantity"
],
"data": [
{
"Category": "Accessories",
"Code": "f230fh0g3",
"Name": "Bamboo Watch",
"Quantity": "24"
},
{
"Category": "Accessories",
"Code": "nvklal433",
"Name": "Black Watch",
"Quantity": "61"
},
{
"Category": "Fitness",
"Code": "zz21cz3c1",
"Name": "Blue Band",
"Quantity": "2"
},
{
"Category": "Clothing",
"Code": "244wgerg2",
"Name": "Blue T-Shirt",
"Quantity": "25"
},
{
"Category": "Accessories",
"Code": "h456wer53",
"Name": "Bracelet",
"Quantity": "73"
},
{
"Category": "Accessories",
"Code": "av2231fwg",
"Name": "Brown Purse",
"Quantity": "0"
},
{
"Category": "Accessories",
"Code": "bib36pfvm",
"Name": "Chakra Bracelet",
"Quantity": "5"
},
{
"Category": "Accessories",
"Code": "mbvjkgip5",
"Name": "Galaxy Earrings",
"Quantity": "23"
},
{
"Category": "Electronics",
"Code": "vbb124btr",
"Name": "Game Controller",
"Quantity": "2"
},
{
"Category": "Electronics",
"Code": "cm230f032",
"Name": "Gaming Set",
"Quantity": "63"
}
]
}
```