Giter Site home page Giter Site logo

jsoncsv's Introduction

jsoncsv : convert json to csv or xlsx

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

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 --help
mkexcel --help

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 sort keys

wait next version

2. mkexcel enable hooks

wait next version

3. csv separator and clean mkexcel args

wait next version

jsoncsv's People

Contributors

alingse avatar

Watchers

ydzhao avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.