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:
= Copy to clipboard Copied!

install:
=

Versions:

  1. 0.1.8 - January 22, 2013 (9.5 KB)
  2. 0.1.7 - July 26, 2012 (9.5 KB)
  3. 0.1.6 - March 27, 2012 (9 KB)
  4. 0.1.5 - March 23, 2012 (9 KB)
  5. 0.1.4 - March 06, 2012 (9 KB)
  6. 0.1.1 - August 24, 2011 (9 KB)
Show all versions (13 total)

Runtime Dependencies (1):

json >= 0

Owners:

Authors:

  • Michael T. Conigliaro

SHA 256 checksum:

fe46fa2171142037cf42d1a61602e86105b2d3076321b447f32637d12378294c

Total downloads 80,545

For this version 3,319

Licenses:

N/A

Required Ruby Version: None

Links: