https://github.com/c-seeger/csv2json
csv2json converter written in go
https://github.com/c-seeger/csv2json
csv csv-parser elk elk-stack json json-export
Last synced: 8 months ago
JSON representation
csv2json converter written in go
- Host: GitHub
- URL: https://github.com/c-seeger/csv2json
- Owner: c-seeger
- License: mit
- Created: 2018-07-10T08:43:49.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2021-08-16T12:36:42.000Z (over 4 years ago)
- Last Synced: 2025-03-24T17:28:37.844Z (12 months ago)
- Topics: csv, csv-parser, elk, elk-stack, json, json-export
- Language: Go
- Size: 18.6 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
# csv2json
[](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=VBXHBYFU44T5W&source=url)
[](https://godoc.org/github.com/c-seeger/csv2json)
[](https://goreportcard.com/report/github.com/c-seeger/csv2json)
[](https://github.com/c-seeger/csv2json/blob/master/LICENSE)
[](https://travis-ci.com/c-seeger/csv2json)
[](https://magefile.org)
is a [CSV](https://en.wikipedia.org/wiki/Comma-separated_values) to [JSON](https://en.wikipedia.org/wiki/JSON) converter inspired by the work of [CSV-To-JSON-Converter](https://github.com/Ahmad-Magdy/CSV-To-JSON-Converter).
This project was created by the intension to create json files from csv for importing the data into an ELK stack since JSON supports more options than CSV for ELK.
## Features
- convert csv to json
- adding additional fields that are not in the original csv file
- options PrettyPrint, QuoteEverything and LineWiseJSON
## Installation
If you already installed GO on your system and configured it properly than its simply:
```
go get github.com/c-seeger/csv2json
```
If not follow [these instructions](https://nats.io/documentation/tutorials/go-install/).
## Usage
### Simple example
The following example reads a csv file defined by -c parameter and outputs to a file defined by -o
```
func main() {
// read and convert csv
f, err := os.Open("test/fixtures/data.csv")
if err != nil {
log.Fatal(err)
}
defer f.Close()
// optional add additional fields
addFields := make(map[string]string)
addFields["addedField"] = "some data"
bytes, err := csv2json.ReadCSV(f, addFields, csv2json.Options{
PrettyPrint: true,
LineWiseJSON: false,
QuoteEverything: false,
})
if err != nil {
log.Fatal(err)
}
fmt.Println(string(bytes))
}
```
### Options
There are some options available in the `csv2json.Options` struct:
```
type Options struct {
LineWiseJSON bool
PrettyPrint bool
QuoteEverything bool
}
```
- LineWiseJSON
- creates a json line per csv line and concats all lines together in one file
- this feature is usefull if you want to generate JSON files from csv's as a data source for an ELK stack
- if this is set to false a jSON array with every line as an entry will be created
- PrettyPrint
- more readable multiline version of json
- QuoteEverything
- ignores any kind of datatypes and quotes everything
## Contribution
Thank you for participating to this project.
Please see our [Contribution Guidlines](https://github.com/c-seeger/csv2json/blob/master/CONTRIBUTING.md) for more information.