RubyGems Navigation menu

jazor 0.1.1

Jazor

Jazor (JSON + razor) is a simple command line JSON parsing tool.

Installation

gem install jazor

Usage

jazor [options] [source] [expression ...]

Options

See the –help command line option.

Sources

The source argument refers to a file, URL or string containing a JSON object. Since attempts to implement a full-featured HTTP client within Jazor would have been futile, Jazor also accepts input from STDIN. This means if you ever need to use an advanced HTTP option that Jazor doesn’t implement, you can always use a real HTTP client (e.g. cURL) and simply pipe the output to Jazor.

Expressions

Jazor accepts one or more Ruby expressions which are simply eval’ed within the context of your JSON object. After Jazor parses your JSON input into native Ruby data types (Hash, Array, etc.), these expressions are used to slice and dice the data any way you want. The results will be “pretty printed” to STDOUT.

Note that hash keys can be accessed via standard Ruby (e.g. foo, foo.fetch(‘bar’), etc.) or Javascript (e.g. foo.bar) syntax.

Expression Testing

Expression testing (–test) allows you to test the “truthiness” of your expression results. If any expression returns a “falsy” value, Jazor will exit with a non-zero return code. This is useful for calling Jazor from within shell scripts.

Examples

$ jazor http://github.com/api/v2/json/commits/list/mconigliaro/jazor/master commits.count
16

$ curl --silent http://github.com/api/v2/json/commits/list/mconigliaro/jazor/master | jazor commits.last.message
initial commit

$ jazor '{ "foo": "abc", "bar": [1, 2, 3] }' 'foo.split(//)'
["a", "b", "c"]

$ jazor '{ "foo": "abc", "bar": [1, 2, 3] }' 'bar.inject { |memo,obj| memo + obj }'
6

$ jazor '[1, 2, 3, 4, 5]' 'select { |obj| obj.even? }'
[2, 4]

$ jazor '[1, 2, 3, 4, 5]' 'select { |obj| obj.odd? }'
[1, 3, 5]

$ jazor '["a", "b", "c"]' self.count
3

Authors

  • Michael T. Conigliaro <mike [at] conigliaro [dot] org>

Contributers

Gemfile:
= Copier Copié!

installation:
=

Versions:

  1. 0.1.8 - January 22, 2013 (9,5 ko)
  2. 0.1.7 - July 26, 2012 (9,5 ko)
  3. 0.1.6 - March 27, 2012 (9 ko)
  4. 0.1.5 - March 23, 2012 (9 ko)
  5. 0.1.4 - March 06, 2012 (9 ko)
  6. 0.1.1 - August 24, 2011 (9 ko)
Voir toutes les versions (13)

Dépendances de Runtime (1):

json >= 0

Propriétaires:

Auteurs:

  • Michael T. Conigliaro

Total de contrôle SHA 256:

fe46fa2171142037cf42d1a61602e86105b2d3076321b447f32637d12378294c

Total de téléchargements 80 616

Pour cette version 3 323

License:

aucune

Version de Ruby requise: None

Liens: