command line tool to convert json to csv
Go Shell
Clone or download
Latest commit d40f54a Mar 22, 2017
Permalink
Failed to load latest commit information.
.gitignore Bump to 1.2.0 Mar 22, 2017
.travis.yml Bump to 1.2.0 Mar 22, 2017
LICENSE MIT license Nov 24, 2015
README.md Bump to 1.2.0 Mar 22, 2017
dist.sh Bump to 1.2.0 Mar 22, 2017
main.go Bump to 1.2.0 Mar 22, 2017
main_test.go Bump to 1.2.0 Mar 22, 2017
string_array.go split -k command line arguments on comma Jan 14, 2013
version.go Bump to 1.2.0 Mar 22, 2017

README.md

json2csv

Converts a stream of newline separated json data to csv format.

Build Status

Installation

pre-built binaries are available under releases.

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

go get github.com/jehiah/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
    -p 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