Skip to main content

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

Project description

jsoncsv : easily convert json to csv or xlsx

https://img.shields.io/pypi/v/jsoncsv.svg https://api.travis-ci.org/alingse/jsoncsv.svg?branch=master https://coveralls.io/repos/github/alingse/jsoncsv/badge.svg

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 on command line

cat raw.json |jsoncsv |mkexcel > output.csv
cat raw.json |jsoncsv |mkexcel -t xls > output.xls

or

jsoncsv raw.json expand.json
mkexcel expand.json -t xls output.xls

more options see –help.

jsoncsv --help
mkexcel --help

just expand/restore the 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

safe mod

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

jsoncsv

use jsoncsv to expand json files to 1 layer json

like this:

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 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 -o output.csv
cat expand.json|mkexcel > output.csv
cat expand.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. 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

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.1.0b0.tar.gz (6.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

jsoncsv-2.1.0b0-py2-none-any.whl (6.5 kB view details)

Uploaded Python 2

File details

Details for the file jsoncsv-2.1.0b0.tar.gz.

File metadata

  • Download URL: jsoncsv-2.1.0b0.tar.gz
  • Upload date:
  • Size: 6.9 kB
  • Tags: Source
  • 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

Hashes for jsoncsv-2.1.0b0.tar.gz
Algorithm Hash digest
SHA256 564170aac1cc274c57afcf656e0bf309826121ff537c3050825cd06447b23bef
MD5 1b1157a87854ef256234c8a88e809b39
BLAKE2b-256 3d13a17b4c2fffbf049726d8d096abe43c77f9211a63e2e0221988ce3e27d727

See more details on using hashes here.

File details

Details for the file jsoncsv-2.1.0b0-py2-none-any.whl.

File metadata

  • Download URL: jsoncsv-2.1.0b0-py2-none-any.whl
  • Upload date:
  • Size: 6.5 kB
  • Tags: Python 2
  • 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

Hashes for jsoncsv-2.1.0b0-py2-none-any.whl
Algorithm Hash digest
SHA256 aad565f8b0b1bc0278c118af71ab6b613025242d57eb5c21fae6fffa4aa88625
MD5 3b044cac6edd74d5202af32421a90ac4
BLAKE2b-256 4ad032ce1294c0fc779da1b540c47e7f802165792ba90c6b51d5b0db7a68e51a

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