json_tree 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in json_tree.gemspec
4
+ gemspec
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/json_tree ADDED
@@ -0,0 +1,42 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require 'open-uri'
5
+ require 'json'
6
+
7
+ class Array
8
+ def self.wrap(object)
9
+ if object.nil?
10
+ []
11
+ elsif object.respond_to?(:to_ary)
12
+ object.to_ary || [object]
13
+ else
14
+ [object]
15
+ end
16
+ end
17
+ end
18
+
19
+ def input
20
+ if ARGV.empty?
21
+ $stdin.read
22
+ else
23
+ open(ARGV[0]).read
24
+ end
25
+ end
26
+
27
+ def print_key(key, level)
28
+ puts "#{level.times.map { |i| '|'}.join(' ')}-- #{key}"
29
+ end
30
+
31
+ def put_hash_keys(hash, indent=1)
32
+ hash.keys.sort.each do |key|
33
+ value = hash[key]
34
+ if value.is_a? Hash
35
+ put_hash_keys(value, indent+1)
36
+ else
37
+ print_key(key, indent)
38
+ end
39
+ end
40
+ end
41
+
42
+ put_hash_keys(Array.wrap(JSON.parse(input)).first)
data/json_tree.gemspec ADDED
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "json_tree/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "json_tree"
7
+ s.version = JsonTree::VERSION
8
+ s.authors = ["Oliver Nightingale"]
9
+ s.email = ["oliver.nightingale1@gmail.com"]
10
+ s.homepage = ""
11
+ s.summary = %q{A simple tool for printing the structure of a JSON object}
12
+ s.description = %q{A simple tool for printing the structure of a JSON object}
13
+
14
+ s.rubyforge_project = "json_tree"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ # specify any dependencies here; for example:
22
+ # s.add_development_dependency "rspec"
23
+ s.add_runtime_dependency "json"
24
+ end
@@ -0,0 +1,3 @@
1
+ module JsonTree
2
+ VERSION = "0.0.1"
3
+ end
data/lib/json_tree.rb ADDED
@@ -0,0 +1,4 @@
1
+ require "json_tree/version"
2
+
3
+ module JsonTree
4
+ end
data/readme.markdown ADDED
@@ -0,0 +1,24 @@
1
+ # JSON Tree
2
+
3
+ JSON Tree will print the structure of a json object.
4
+
5
+ ## Usage
6
+
7
+ Can read from stdin:
8
+
9
+ $ echo '{"foo": 1, "bar": 2}' | json_tree
10
+
11
+ Outputs:
12
+
13
+ |-- bar
14
+ |-- foo
15
+
16
+ can also read from a file or uri:
17
+
18
+ $ json_tree http://example.com/some_json_doc.json
19
+
20
+ If the JSON passed to json tree is an array it pulls out the first object in the array and displays its keys.
21
+
22
+ ## Todo
23
+
24
+ Almost everything, this is very simple at the moment.
metadata ADDED
@@ -0,0 +1,65 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: json_tree
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Oliver Nightingale
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-01-31 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: json
16
+ requirement: &70305490511880 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70305490511880
25
+ description: A simple tool for printing the structure of a JSON object
26
+ email:
27
+ - oliver.nightingale1@gmail.com
28
+ executables:
29
+ - json_tree
30
+ extensions: []
31
+ extra_rdoc_files: []
32
+ files:
33
+ - .gitignore
34
+ - Gemfile
35
+ - Rakefile
36
+ - bin/json_tree
37
+ - json_tree.gemspec
38
+ - lib/json_tree.rb
39
+ - lib/json_tree/version.rb
40
+ - readme.markdown
41
+ homepage: ''
42
+ licenses: []
43
+ post_install_message:
44
+ rdoc_options: []
45
+ require_paths:
46
+ - lib
47
+ required_ruby_version: !ruby/object:Gem::Requirement
48
+ none: false
49
+ requirements:
50
+ - - ! '>='
51
+ - !ruby/object:Gem::Version
52
+ version: '0'
53
+ required_rubygems_version: !ruby/object:Gem::Requirement
54
+ none: false
55
+ requirements:
56
+ - - ! '>='
57
+ - !ruby/object:Gem::Version
58
+ version: '0'
59
+ requirements: []
60
+ rubyforge_project: json_tree
61
+ rubygems_version: 1.8.11
62
+ signing_key:
63
+ specification_version: 3
64
+ summary: A simple tool for printing the structure of a JSON object
65
+ test_files: []