json2csv

package module
v1.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 25, 2023 License: MIT Imports: 11 Imported by: 0

README

json2csv

Converts a stream of newline separated json data to csv format. Forks from jehiah/json2csv and make some incompatible changes.

Installation

pre-built binaries are available under releases.

If you have a working golang install, you can use go get.

go get github.com/haotrr/json2csv/cmd
mv $GOPATH/bin/cmd $GOPATH/bin/json2csv

Usage

usage: json2csv
    -k fields,and,nested.fields,to,output
    -i /path/to/input.json (optional; default is stdin)
    -o /path/to/output.csv (optional; default is stdout)
    --version
    -H print csv header row
    -h This help

To convert:

{"user": {"name":"jehiah", "password": "root"}, "remote_ip": "127.0.0.1", "dt" : "[20/Aug/2010:01:12:44 -0400]"}
{"user": {"name":"jeroenjanssens", "password": "123"}, "remote_ip": "192.168.0.1", "dt" : "[20/Aug/2010:01:12:44 -0400]"}
{"user": {"name":"unknown", "password": ""}, "remote_ip": "76.216.210.0", "dt" : "[20/Aug/2010:01:12:45 -0400]"}

to:

"jehiah","127.0.0.1"
"jeroenjanssens","192.168.0.1"
"unknown","76.216.210.0"

you would either

json2csv -k user.name,remote_ip -i input.json -o output.csv

or

cat input.json | json2csv -k user.name,remote_ip > output.csv

Package

func Do(inputFile, outputFile, outputDelim string, allKeys boo, keys []string, printHeader bool) (int, error)

Documentation

Index

Constants

View Source
const (
	Stdin  = ""
	Stdout = ""
)

Variables

This section is empty.

Functions

func Do

func Do(inputFile, outputFile, outputDelim string, allKeys bool, keys []string, printHeader bool) (int, error)

Types

type LineReader

type LineReader interface {
	ReadBytes(delim byte) (line []byte, err error)
}

type StringArray

type StringArray []string

func (*StringArray) Set

func (a *StringArray) Set(s string) error

func (*StringArray) String

func (a *StringArray) String() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL