Sha256: f6237eee6b3b50188963abaf8edc858134ece3e6a75abf1c4a2b77fd5fe9c8db

Contents?: true

Size: 932 Bytes

Versions: 26

Compression:

Stored size: 932 Bytes

Contents

#!/usr/bin/env ruby


# Reads json strings (one per line) from stdin.
# you pass keys as arguments and those are printed out as columns.

require 'rubygems'
require 'json'

$stdout.sync = true

STDIN.each_line do |line|
  begin
    next unless line.include?('}')
    object = JSON.parse(line)
    string = []
    ARGV.each do |argument|
      if object[argument]
        if object[argument].is_a?(String)
          string.push(object[argument])
        elsif object[argument].is_a?(Array)
          object[argument].each do |element|
            string.push("\n" + element.to_json) # will break if not an object!
          end
        else
          string.push(object[argument].to_json)
        end
      else
        string.push(argument)
      end
    end
    if string.size > 0
      puts string.join(" ")
    end
  rescue => error
  # $stderr.puts line
  # $stderr.puts error.message
  # $stderr.puts error.backtrace
  end
end

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
ix-cli-0.0.27 bin/ix-json-key
ix-cli-0.0.26 bin/ix-json-key
ix-cli-0.0.25 bin/ix-json-key
ix-cli-0.0.24 bin/ix-json-key
ix-cli-0.0.23 bin/ix-json-key
ix-cli-0.0.22 bin/ix-json-key
ix-cli-0.0.21 bin/ix-json-key
ix-cli-0.0.20 bin/ix-json-key
ix-cli-0.0.19 bin/ix-json-key
ix-cli-0.0.18 bin/ix-json-key
ix-cli-0.0.17 bin/ix-json-key
ix-cli-0.0.16 bin/ix-json-key
ix-cli-0.0.15 bin/ix-json-key
ix-cli-0.0.14 bin/ix-json-key
ix-cli-0.0.13 bin/ix-json-key
ix-cli-0.0.12 bin/ix-json-key
ix-cli-0.0.11 bin/ix-json-key
ix-cli-0.0.10 bin/ix-json-key
ix-cli-0.0.9 bin/ix-json-key
ix-cli-0.0.7 bin/ix-json-key