Sha256: 015dee1ee440ee871b4a1bf4b736e39b9bde55e79867d3d50d868e6ba348214a

Contents?: true

Size: 579 Bytes

Versions: 22

Compression:

Stored size: 579 Bytes

Contents

#!/usr/bin/env ruby
# frozen_string_literal: true

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

22 entries across 22 versions & 2 rubygems

Version Path
iso-jsonpath-1.1.7 bin/jsonpath
iso-jsonpath-1.1.6 bin/jsonpath
jsonpath-1.1.5 bin/jsonpath
jsonpath-1.1.4 bin/jsonpath
jsonpath-1.1.3 bin/jsonpath
jsonpath-1.1.2 bin/jsonpath
jsonpath-1.1.0 bin/jsonpath
jsonpath-1.0.7 bin/jsonpath
jsonpath-1.0.6 bin/jsonpath
jsonpath-1.0.5 bin/jsonpath
jsonpath-1.0.4 bin/jsonpath
jsonpath-1.0.3 bin/jsonpath
jsonpath-1.0.2 bin/jsonpath
jsonpath-1.0.1 bin/jsonpath
jsonpath-1.0.0 bin/jsonpath
jsonpath-0.9.9 bin/jsonpath
jsonpath-0.9.8 bin/jsonpath
jsonpath-0.9.7 bin/jsonpath
jsonpath-0.9.6 bin/jsonpath
jsonpath-0.9.5 bin/jsonpath