Skip to main content

a command tool easily convert json file to csv or xlsx

Project description

https://img.shields.io/pypi/v/jsoncsv.svg

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

cat expand.json|jsoncsv -r > raw.json

cat raw.json|jsoncsv --safe|mkexcel > output.csv


jsoncsv --help

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 .

–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

将**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/TODO

1. key can’t be all intenger string

example:

echo '{"0":1,"1":[1,2]}'|jsoncsv -e| jsoncsv -r
[1, [1, 2]]

如果要考虑,实现方案会过于复杂,不想考虑在expand的json中添加类型信息

2. write in xlsx is always str

wait next version

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

jsoncsv-2.0.4.tar.gz (5.3 kB view details)

Uploaded Source

File details

Details for the file jsoncsv-2.0.4.tar.gz.

File metadata

  • Download URL: jsoncsv-2.0.4.tar.gz
  • Upload date:
  • Size: 5.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for jsoncsv-2.0.4.tar.gz
Algorithm Hash digest
SHA256 db3bd1cce910e9f7a4d84eb3688552dc16057fc5354d4760aa7823927f6cc1ec
MD5 e624d2535e827e82ad6d566925a5b94a
BLAKE2b-256 523453e1eef82852aa54605a59455055f5c30e711fad0ce6b20f52f48f340e8e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page