Sha256: ac54fe6c7a52f8df09820055cff1745f813cee09c3c1a4c1cf3ffaca8d3a2ccd

Contents?: true

Size: 549 Bytes

Versions: 16

Compression:

Stored size: 549 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

16 entries across 16 versions & 1 rubygems

Version Path
jsonpath-0.9.2 bin/jsonpath
jsonpath-0.9.1 bin/jsonpath
jsonpath-0.9.0 bin/jsonpath
jsonpath-0.8.12 bin/jsonpath
jsonpath-0.8.11 bin/jsonpath
jsonpath-0.8.10 bin/jsonpath
jsonpath-0.8.8 bin/jsonpath
jsonpath-0.8.7 bin/jsonpath
jsonpath-0.8.6 bin/jsonpath
jsonpath-0.8.5 bin/jsonpath
jsonpath-0.8.4 bin/jsonpath
jsonpath-0.8.3 bin/jsonpath
jsonpath-0.8.2 bin/jsonpath
jsonpath-0.7.2 bin/jsonpath
jsonpath-0.7.1 bin/jsonpath
jsonpath-0.7.0 bin/jsonpath