Skip to main content

a command tool easily convert json file to csv or xlsx

Project description


jsoncsv : convert json to csv or xlsx
=================================================

.. image:: https://img.shields.io/pypi/v/jsoncsv.svg
:target: https://pypi.python.org/pypi/jsoncsv

.. image:: https://api.travis-ci.org/alingse/jsoncsv.svg?branch=master

.. image:: https://coveralls.io/repos/github/alingse/jsoncsv/badge.svg
:target: https://coveralls.io/github/alingse/jsoncsv


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

.. code-block:: bash

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

just expand/restore the json

.. code-block:: bash

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)

.. code-block:: bash

mkexcel expand.json output.csv
mkexcel -t xls expand.json > output.xls

safe mod

.. code-block:: bash

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

jsoncsv --help
mkexcel --help

jsoncsv
>>>>>>>>

use jsoncsv to expand json files to 1 layer json

like this:

.. code-block:: bash

echo '{"s":[1,2,{"w":1}]}'|jsoncsv
{"s.2.w": 1,"s.0": 1,"s.1": 2}


-e, --expand
-------------

expand json, 展开 json

.. code-block:: bash

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

.. code-block:: bash

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

.. code-block:: bash

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']

.. code-block:: bash

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:

.. code-block:: bash

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


2. mkexcel enable sort keys
-----------------------------------------

wait next version

2. mkexcel enable hooks
-----------------------------------------

wait next version

3. csv separator and clean mkexcel args
-----------------------------------------

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

Uploaded Source

File details

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

File metadata

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

File hashes

Hashes for jsoncsv-2.0.8b0.tar.gz
Algorithm Hash digest
SHA256 e191014b56becf08f4f6df3132faccc270b082f0c3c9e9396510b49070d7933c
MD5 56053476b923076766d71b54da64878b
BLAKE2b-256 9c9f38cc1cf51ad6154dd2f95ea4cebe1016f7dde8cdefb65473c3b0edc58696

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