Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/birchb1024/json2csv

Convert JSON data to CSV data easily
https://github.com/birchb1024/json2csv

Last synced: 2 days ago
JSON representation

Convert JSON data to CSV data easily

Awesome Lists containing this project

README

        

# json2csv

Convert JSON data to CSV data easily

# Usage

`json2csv` is a simple filter reading from standard input and sending to standard output.

```
$ json2csv outputfile
```
Usage of json2csv:

`-dedupe`
Remove duplicate rows. Usage: -dedupe=false (default true)

`-index` string
List index column name part. (default "#")

`-list` string
List column name part. (default "LIST")

`-separator` string
column name internal separator. (default ".")

# Description

`json2csv` works for JSON files which are already organized into simple record structures.

```JSON
[
{ "Title": "The Life of Brian",
"date": { "year": "1908", "month": "January"},
"cast" : [ "Joanna Lumley", "Terrance Trent Darby" ]
},
{ "Title": "The Life of Pi",
"date": { "year": "2012", "month": "January"},
"cast" : ["Suraj Sharma", "Nota Tiger" ]
}
]
```

The map keys are expected to become column names (not values), the map values are
mapped to cells. Nested maps result in compound column names. Embedded lists have a
row per each item in the list. The above is output as:

```
LIST,LIST.#,LIST.Title,LIST.date.year,LIST.cast.LIST,LIST.date.month,LIST.cast.LIST.#
,1,The Life of Brian,1908,Joanna Lumley,January,1
,1,The Life of Brian,1908,Terrance Trent Darby,January,2
,2,The Life of Pi,2012,Suraj Sharma,January,1
,2,The Life of Pi,2012,Nota Tiger,January,2
```

Here's the pretty version:

|LIST|LIST.#|LIST.Title |LIST.date.year|LIST.cast.LIST |LIST.date.month|LIST.cast.LIST.#|
|----|------|-----------------|--------------|--------------------|---------------|----------------|
| |1 |The Life of Brian|1908 |Joanna Lumley |January |1 |
| |1 |The Life of Brian|1908 |Terrance Trent Darby|January |2 |
| |2 |The Life of Pi |2012 |Suraj Sharma |January |1 |
| |2 |The Life of Pi |2012 |Nota Tiger |January |2 |

# Column names

The column names format can be altered to avoid issues by using the command-line options.
Example:
```
$ ./json2csv -list 'items' -index number -separator '_'