https://github.com/wwcd/csv2json
csv2json
https://github.com/wwcd/csv2json
csv2json golang
Last synced: about 1 year ago
JSON representation
csv2json
- Host: GitHub
- URL: https://github.com/wwcd/csv2json
- Owner: wwcd
- Created: 2020-08-01T16:30:38.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2020-08-01T16:31:07.000Z (over 5 years ago)
- Last Synced: 2023-03-21T20:13:30.288Z (about 3 years ago)
- Topics: csv2json, golang
- Language: Go
- Homepage:
- Size: 7.81 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
### CSV2JSON
#### Cmd Usage
```txt
❯ cat input.csv
h1,h2,h3,h4
a,b,c,d
aa,bb,cc,dd
aaa,bbb,ccc,ddd
aaaa,bbbb,cccc,dddd
aaaaa,bbbbb,ccccc,ddddd
❯ ./csv2json input.csv --from-col=1 --to-col=2 --from-row=1 --to-row=2 | jq .
[
{
"h2": "b",
"h3": "c"
},
{
"h2": "bb",
"h3": "cc"
}
]
```
---
#### Lib Usage
```go
input := `h1,h2,h3,h4
a,b,c,d
aa,bb,cc,dd
aaa,bbb,ccc,ddd
aaaa,bbbb,cccc,dddd
aaaaa,bbbbb,ccccc,ddddd`
output := &bytes.Buffer{}
err := csv2json.Conv(bytes.NewBufferString(input), output, With(1,2), WithRow(2,3))
if err != nil {
panic(err)
}
// OUTPUT: [{"h2":"bb","h3":"cc"},{"h2":"bbb","h3":"ccc"}]
fmt.Println(output.String())
```