Sha256: 9168e1f979c9a183845e54677d0c4004586a9270b9f8c4c0ca31de132eb54bc1

Contents?: true

Size: 580 Bytes

Versions: 4

Compression:

Stored size: 580 Bytes

Contents

#!/usr/local/env ruby

require 'jsonpath'
require 'multi_json'

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 MultiJson.encode(jsonpath.on(MultiJson.decode(STDIN.readline)))
  end
when String
  puts MultiJson.encode(jsonpath.on(MultiJson.decode(File.exist?(ARGV[1]) ? File.read(ARGV[1]) : ARGV[1])))
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
jsonpath-0.5.1 bin/jsonpath
jsonpath-0.5.0 bin/jsonpath
jsonpath-0.4.2 bin/jsonpath
jsonpath-0.4.1 bin/jsonpath