A command tool easily convert json file to csv or xlsx.


Keywords
jsoncsv, jsontocsv, json2csv, convert, json2xls, csv, json, json2excel, tools
License
Apache-2.0
Install
pip install jsoncsv==2.2.5

Documentation

jsoncsv : easily convert json to csv or xls[x]

pypi build coverage

jsoncsv (with mkexcel) is a command tool to convert json file to csv/xlsx file.

It's simple, and no need user to specify the keys.

Just use them.

Quick Start :

Cat the raw.json to csv/xls use command line tool

Each line of raw json text file is a json object

Jsoncsv will output a csv file

id,name,year,zone
1,A,2015,
2,S,,china

This is easily and needn't care the different keys from any two object.

For Json Array

If input file is an json_array, use -A/--array to decode it

Input File

Output File

id,name,year,zone
1,A,2015,
2,S,,china

Step by Step

get more options with --help.

Install

Usage

see #QuickStart and get more options with --help.

just expand/restore the json, the expand json is one layer json.

mkexcel the expanded json (one layer)

-e, --expand

expand json, 展开 json

{"s":[1,2,{"w":1}]} will transformed to {"s.2.w": 1,"s.0": 1,"s.1": 2}

the output "expand.json" is only one layer json, it can be easy change to csv or xlsx (with mkexcel)

-r, --restore

restore the expanded json 重构被展开的json

{"s.2.w": 1,"s.0": 1,"s.1": 2} change to {"s":[1,2,{"w":1}]}

-s, --separator

separator used for combine the keys in the tree

default separator is .

--safe

on safe mode, use escape separator to avoid confilct

expand:

['aa', 'bb', 'www.xxx.com'] --> 'aa\.bb\.www.xxx.com'

restore:

'aa\.bb\.www.xxx.com' --> ['aa', 'bb', 'www.xxx.com']

mkexcel

dump expanded (by jsoncsv) json file to csv or xls file

-t, --type

chose dump type in ['csv', 'xls'] default is 'csv'

NOTE/TODO

1. dict keys can't be just array indexes

example:

2. mkexcel enable hooks

wait next next version

3. unicodecsv is not good enough

but better than python strand library csv.

4. Windows is poor support

see #37

try use https://jsoncsv-web.vercel.app instead