Sha256: b2ac7f1cec5e4b95664b43ee2482926787689352980061dcdf42652923ef0d8f

Contents?: true

Size: 586 Bytes

Versions: 1

Compression:

Stored size: 586 Bytes

Contents

#!/usr/local/env ruby

require 'jsonpath'
require 'yajl'

def usage
  puts "jsonpath [expression] (file|string)

If you omit the second argument, it will read stdin, assuming one valid JSON object
per line. Expression must be a valid jsonpath expression."
  exit!
end

usage unless ARGV[0]

jsonpath = JsonPath.new(ARGV[0])
case ARGV[1]
when nil #stdin
  until STDIN.eof?
    puts Yajl::Encoder.encode(jsonpath.on(Yajl::Parser.parse(STDIN.readline)))
  end
when String
  puts Yajl::Encoder.encode(jsonpath.on(Yajl::Parser.parse(File.exist?(ARGV[1]) ? File.read(ARGV[1]) : ARGV[1])))
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
jsonpath-0.4.0 bin/jsonpath