A command tool easily convert json file to csv or xlsx.
Project description
jsoncsv : easily convert json to csv or xls[x]
jsoncsv && mkexcel is a command tool to convert json file to csv/xlsx file.
It’s simple, and no need user to specify the keys. :)
Quick Start :
cat the raw.json to csv/xls use command line tool
each line of raw json text file is a json object.
# raw json text,(each line is a json object)
# {"id":1, "name":"A"}
# {"id":2, "name":"S"}
cat raw.json | jsoncsv | mkexcel > output.csv
cat raw.json | jsoncsv | mkexcel -t xls > output.xls
a another example
echo '{"user":{"id":1,"name":"A"},"week":52}\n{"user":{"id":1,"name":"S"}, "year":2015}'|jsoncsv
# {"user.id": 1, "user.name": "A", "week": 52}
# {"user.id": 1, "user.name": "S", "year": 2015}
echo '{"user":{"id":1,"name":"A"},"week":52}\n{"user":{"id":1,"name":"S"}, "year":2015}'|jsoncsv|mkexcel
# user.id,user.name,week,year
# 1,A,52,
# 1,S,,2015
or
jsoncsv raw.json expand.json
mkexcel expand.json -t xls output.xls
more options see –help.
jsoncsv --help
mkexcel --help
Install
pip install jsoncsv
Usage
just expand/restore the json, the expand json is one layer json.
jsoncsv raw.json expand.json
jsoncsv -r expand.json raw.json
cat raw.json|jsoncsv |jsoncsv -r > raw2.json
mkexcel the expanded json (one layer)
mkexcel expand.json output.csv
mkexcel -t xls expand.json > output.xls
mkexcel -t csv expand.json > output.csv
jsoncsv
use jsoncsv to expand json files to 1 layer json
jsoncsv raw.json expand.json
-e, –expand
expand json, 展开 json
jsoncsv -e raw.json expand.json
cat raw.json expand.json
{"s":[1,2,{"w":1}]}
{"s.2.w": 1,"s.0": 1,"s.1": 2}
{“s”:[1,2,{“w”:1}]} transformed to {“s.2.w”: 1,”s.0”: 1,”s.1”: 2}
expand.json is only one layer json, it can be easy change to csv or xlsx
-r,–restore
restore the expanded json 重构被展开的json
jsoncsv -r expand.json raw.json
cat expand.json raw.json
{"s.2.w": 1,"s.0": 1,"s.1": 2}
{"s": [1, 2, {"w": 1}]}
{“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
mkexcel expand.json output.csv
-t,–type
chose dump type in [‘csv’, ‘xls’] default is ‘csv’
cat expand.json|mkexcel -t csv > output.csv
cat expand.json|mkexcel -t xls > output.xls
NOTE/TODO
1. dict keys can’t be just array indexes
example:
echo '{"0":1,"1":[1,2]}'|jsoncsv -e| jsoncsv -r
[1, [1, 2]]
2. mkexcel enable hooks
wait next version
3. unicodecsv is not good enough
but better than python strand library csv.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file jsoncsv-2.2.0b0-py2.py3-none-any.whl.
File metadata
- Download URL: jsoncsv-2.2.0b0-py2.py3-none-any.whl
- Upload date:
- Size: 11.0 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.4.2 requests/2.19.1 setuptools/41.0.1 requests-toolbelt/0.8.0 tqdm/4.23.4 CPython/2.7.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f69bfcfe5039f5a1fdfb6fa3320c0177ee0800ab4a0e835e825146f46a1f645e
|
|
| MD5 |
53fa17dfb81a2a8e4641b220ac7f7f95
|
|
| BLAKE2b-256 |
0a11179f3729a6e3b06dbd5c5a296504e9f7cf6ace3fc9e9140c496570b01309
|