Sha256: c4954a3e5927323c1bdbf67e5ecee532debecbf3e43507950ef73b62681642dd

Contents?: true

Size: 548 Bytes

Versions: 2

Compression:

Stored size: 548 Bytes

Contents

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

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
jsonpath-0.5.8 bin/jsonpath
jsonpath-0.5.7 bin/jsonpath