• Stars
    star
    216
  • Rank 183,179 (Top 4 %)
  • Language Awk
  • License
    MIT License
  • Created almost 11 years ago
  • Updated about 8 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A Bash command line tool for converting JSON to CSV

jsonv.sh

A Bash command line tool for converting JSON to CSV

Installation

Run the following command to install jsonv:

$ curl -Ls https://raw.github.com/archan937/jsonv.sh/master/install.sh | bash

To uninstall, run this command:

$ curl -Ls https://raw.github.com/archan937/jsonv.sh/master/uninstall.sh | bash

Note: You also need to install gawk.

Usage

Call jsonv and pass the paths of the values used for the CSV columns (comma separated). Optionally, you can pass a prefix for the paths as a second argument.

Simple JSON

Parsing examples/simple.json (3 objects) without a path prefix:

$ curl -Ls https://raw.github.com/archan937/jsonv.sh/master/examples/simple.json | jsonv id,name,age
1,"Dagny Taggart",39
8,"Francisco D'Anconia",40
12,"Hank Rearden (a.k.a \"The Tank\")",46

Complex JSON

Parsing examples/complex-1.json (1008 objects, file size 764KB) with a path prefix:

$ curl -Ls https://raw.github.com/archan937/jsonv.sh/master/examples/complex-1.json | jsonv person.id,person.name,person.gender,person.balance,person.age,person.company response.data
1,"Anastasia Goodwin","female","$2,623.00",20,"Equitax"
2,"Peters Watson","male","$1,606.00",29,"Blurrybus"
3,"Shirley Gates","female","$3,735.00",25,"Omatom"
4,"Mcgowan Terry","male","$3,121.00",25,"Austech"
5,"Melody Cote","female","$1,519.00",25,"Matrixity"
...

Parsing examples/complex-2.json (4734 objects, file size 3.2MB) with a path prefix:

$ curl -Ls https://raw.github.com/archan937/jsonv.sh/master/examples/complex-2.json | jsonv id,name,gender,balance,age,company,address,phone,email,picture,registered response.data
1,"Newton Bush","male","$1,653.00",27,"Xanide","710 Corbin Place, Vivian, Mississippi, 6954","+1 (916) 520-2940","[email protected]","http://placehold.it/32x32","1998-02-17T17:00:12 -01:00"
2,"Ratliff Workman","male","$2,941.00",39,"Bitendrex","680 Menahan Street, Matheny, North Dakota, 3316","+1 (997) 409-2099","[email protected]","http://placehold.it/32x32","1996-02-02T13:26:48 -01:00"
3,"Hawkins Jacobs","male","$1,584.00",40,"Marqet","349 Joralemon Street, Mansfield, California, 8655","+1 (831) 508-2216","[email protected]","http://placehold.it/32x32","2012-07-23T15:13:43 -02:00"
4,"Whitfield Maldonado","male","$2,519.00",34,"Tri@Tribalog","966 Moffat Street, Wanamie, Indiana, 3006","+1 (940) 554-2482","whitfieldmaldonado@[email protected]","http://placehold.it/32x32","2002-11-06T13:40:49 -01:00"
5,"Wise Phelps","male","$1,322.00",23,"Temorak","116 Matthews Court, Orin, Kentucky, 2196","+1 (967) 577-3292","[email protected]","http://placehold.it/32x32","1997-11-20T21:58:48 -01:00"
...

Trying it out locally

Check out this repository first and run the following command:

$ cat examples/complex-3.json | ./jsonv id,name,gender,balance,age,company,address,phone,email,picture,registered response.data
1,"Pearlie Hodge","female","$1,347.00",36,"Zappix","371 Abbey Court, Leola, Iowa, 6919","+1 (966) 515-2796","[email protected]","http://placehold.it/32x32","2004-05-18T01:48:01 -02:00"
2,"Tessa Saunders","female","$1,398.00",24,"Zounds","399 Provost Street, Ironton, Alaska, 4909","+1 (807) 501-3914","[email protected]","http://placehold.it/32x32","2001-11-27T14:20:43 -01:00"
3,"Clarissa Hawkins","female","$2,974.00",33,"Recrisys","566 Drew Street, Elliston, Maine, 9520","+1 (867) 510-2236","[email protected]","http://placehold.it/32x32","2002-09-12T12:01:35 -02:00"
4,"Lauren Sexton","female","$2,282.00",26,"Lunchpad","461 Lloyd Street, Deercroft, Arkansas, 9022","+1 (937) 509-3538","[email protected]","http://placehold.it/32x32","1998-07-01T19:13:55 -02:00"
5,"Hutchinson Ayers","male","$1,697.00",20,"Mangelica","129 Tabor Court, Freeburn, North Dakota, 2921","+1 (823) 542-2366","[email protected]","http://placehold.it/32x32","1997-11-20T04:39:49 -01:00"
...

In this example, examples/complex-3.json contains 19828 objects (file size 13.6MB) and is parsed in about 20 seconds.

Log file

When using jsonv, it writes log messages to log file jsonv.log located within the same directory as jsonv itself.

=====================
[2013-12-07 04:10:29] Writing JSON file
[2013-12-07 04:10:31] Writing tokens file
[2013-12-07 04:10:32] Deriving keys
[2013-12-07 04:10:32] Deriving prefix
[2013-12-07 04:10:32] Counting entries
[2013-12-07 04:10:32] Writing map file
[2013-12-07 04:10:32] Deriving line format
[2013-12-07 04:10:32] Compiling CSV output
[2013-12-07 04:10:32] Done.
=====================

Credits

jsonv heavily makes use of JSON.awk created by Stepk (step-):

https://github.com/step-/JSON.awk

Thanks Dominic Tarr (@dominictarr) for creating JSON.sh on which JSON.awk is based on:

https://github.com/dominictarr/JSON.sh

Thanks GNU Project (http://www.gnu.org) for creating gawk:

http://www.gnu.org/software/gawk

License

Copyright (c) 2013 Paul Engel, released under the MIT license

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

More Repositories

1

templayed.js

The fastest and smallest Mustache compliant Javascript templating library written in 2167 bytes (uncompressed)
JavaScript
336
star
2

csonv.js

A tiny library to fetch relational CSV data at client-side just like JSON
JavaScript
271
star
3

ruby-mass

Introspect the Ruby Heap by indexing, counting, locating references to and detaching (in order to release) objects - optionally narrowing by namespace
Ruby
246
star
4

topup

The #1 Javascript Pop Up / Lightbox made by Paul Engel
JavaScript
159
star
5

motion-bundler

Use Ruby gems and mock require statements within RubyMotion applications
Ruby
98
star
6

clickhouse

A Ruby database driver for Clickhouse
JavaScript
89
star
7

stack_tracy

Investigate and detect slow methods within the stack trace of your Ruby (optionally Sinatra) application
Ruby
77
star
8

mecks_unit

A simple Elixir package to elegantly mock module functions within (asynchronous) ExUnit tests using Erlang's :meck library
Elixir
55
star
9

ex_united

Easily spawn Elixir nodes (supervising, Mix configured, easy asserted / refuted) within ExUnit tests
Elixir
43
star
10

rich_cms

Enrichments (e9s) module for a pluggable CMS frontend
Ruby
42
star
11

e9s

Enrichments (e9s) for a pluggable CMS, internationalization (i18n) and localized pluralization
Ruby
40
star
12

jazz_libs

A small gem for rolling out JS libraries (includes repository, demo page and version release rake task)
Ruby
38
star
13

slot_machine

Ruby gem for matching available slots (time slots are also supported)
Ruby
24
star
14

lock-o-motion

Require and mock Ruby gems (including their dependencies) within RubyMotion applications
Ruby
23
star
15

dirty_hashy

Dirty tracking within hashes (with or without indifferent access) or objects as it is expected to be!
Ruby
15
star
16

animate.js

Add slick animations to your web pages and page transitions
JavaScript
14
star
17

raccoon_tip

A lightweight jQuery based balloon tip library
JavaScript
9
star
18

jzip

A Rails gem for Javascript merging and compression using templates (like SASS)
JavaScript
9
star
19

e9s-demo

Rails 3 (and also Rails 2) demo application of the Enrichments (e9s) gem
JavaScript
9
star
20

rich_pluralization

Enrichments (e9s) module for localized pluralization
Ruby
9
star
21

rich_i18n

Enrichments (e9s) module for i18n
Ruby
9
star
22

designer.js

A minimalistic Javascript library to design web pages using absolute positioning
JavaScript
8
star
23

bugs_bunny

A Unicorn served Sinatra demo app which uses Bunny to broadcast AMQP messages to every worker
Ruby
7
star
24

monetdb

A pure Ruby database driver for MonetDB (monetdb5-sql)
Ruby
6
star
25

cached_record

Cache (and optionally memoize) ActiveRecord or DataMapper records in Redis or Memcached
Ruby
5
star
26

seat_holder

The modest Javascript placeholder
JavaScript
4
star
27

unextendable

A small gem making unextending extended module methods within object instances possible
Ruby
4
star
28

relexer.js

A very simple Javascript lexer and parser
JavaScript
4
star
29

oned.js

Trigger callback functions when native HTML or jQuery elements get added to the DOM tree
JavaScript
3
star
30

webhead

An easy-to-use Node web crawler storing cookies, following redirects, traversing pages and submitting forms.
JavaScript
3
star
31

vps

Zero-config deployments of Plug, Phoenix, Rack and Rails apps on a clean Ubuntu server using Docker and Let's Encrypt
Ruby
2
star
32

directiveadmin

A layer on top of ActiveAdmin for adding more power and flexibility (opinionated customizations)
Ruby
2
star
33

rich_support

A small gem making your own gem Rails 2 and 3 compliant and providing the String class a few goodies
Ruby
2
star
34

portcat

Alpine based Docker container with socat installed that can easily map multiple ports to another container
Shell
2
star
35

el.js

A straightforward and lightweight Javascript library for data-binded template rendering
JavaScript
2
star
36

google-apis

A thin layer on top of Google::APIClient for a more intuitive way of working (e.g. with BigQuery or Cloud Storage)
Ruby
2
star
37

directiverecord

A layer on top of ActiveRecord for using paths within queries without thinking about association includes
Ruby
2
star
38

iRacingHUD

Create your own reactive Javascript based UI iRacing HUDs
JavaScript
2
star
39

clustorage

Elixir cluster to store and distribute data and functions by code compilation and hot loading done by a designated "loader node"
Elixir
2
star
40

new_class

Define variable dependent classes without evalling
Ruby
1
star
41

dollar.js

A minimalistic Javascript library for DOM manipulation, template rendering (data binded), event binding, introspection
JavaScript
1
star
42

gem_suit

Test the entire usage workflow (including generators) of your newly generated or existing gem within Rails 2 and 3.
Ruby
1
star