a tool convert json file to csv or xlsx
Project description
jsoncsv is a command tool to convert json file to csv or xlsx file.
It has not ready to be use as a module. :(
command line example :
$cat raw.json|jsoncsv|mkexcel > output.csv
$cat raw.json|jsoncsv|mkexcel -t xls > output.xls
$jsoncsv raw.json expand.json
$mkexcel expand.json -o output.csv
$mkexcel expand.json -t xls -o output.csv
jsoncsv
example:
$echo '{"s":[1,2,{"w":1}]}'|jsoncsv
{"s.2.w": 1,"s.0": 1,"s.1": 2}
-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 重构被展开的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 .
mkexcel
dump expanded (by jsoncsv) json file to csv or xls
将**jsoncsv** expand 的 json文件转成 csv/xls
mkexcel expand.json -o output.csv
cat expand.json|mkexcel > output.csv
cat expnad.json|mkexcel -t xls > output.xls
-t,–type
chose dump type in [‘csv’, ‘xls’]
cat expand.json|mkexcel -t csv > output.csv
cat expand.json|mkexcel -t xls > output.xls
NOTE
1. key in origin json can’t contain separator
原始json 的 各级key不能包含分隔符 “.”,因为`.`是expand后key的连接字符。 下个版本会考虑这个问题,可能会使用转义
s.w.www.xxx.com –>s.w.www.xxx.com
2. key can’t be all intenger string
字典key中不能混杂数字。如果全部的key都是数字,恢复重构时会被当成list类型。
example:
echo '{"0":1,"1":[1,2]}'|jsoncsv -e| jsoncsv -r
[1, [1, 2]]
实现方案会过于复杂,不想考虑在expand的json中添加类型信息
3. write in xlsx is always str
下个版本会考虑
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 Distribution
File details
Details for the file jsoncsv-2.0.3.tar.gz.
File metadata
- Download URL: jsoncsv-2.0.3.tar.gz
- Upload date:
- Size: 4.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e8ecec3aaaba181f5c0f342ea31c264cbf918f87113871f01cfa6540939e28f9
|
|
| MD5 |
b80956c6093fe36096126474307b707d
|
|
| BLAKE2b-256 |
bbcf9ab8dc9aae0ae46eb51451e808b6cf0d564417123ef4bb34cc3f47db4912
|