8000 GitHub - scblur869/csv-2-json: an API written in Go that reads a CSV file and sends a json response
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

an API written in Go that reads a CSV file and sends a json response

Notifications You must be signed in to change notification settings

scblur869/csv-2-json

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

type CSVData struct {
 Header []string                 `json:"header"`
 Rows   []map[string]interface{} `json:"data"`
}

Single Endpoint

POST   /api/v1/upload
multipart/form-data;

example

CSV File

"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

{
    "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"
        }
    ]
}

About

an API written in Go that reads a CSV file and sends a json response

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published
0