Skip to content

Instantly share code, notes, and snippets.

@gkop
Last active August 29, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gkop/9628598 to your computer and use it in GitHub Desktop.
Save gkop/9628598 to your computer and use it in GitHub Desktop.
Debug json API response with object in pry
#!/usr/bin/env ruby
# Usage:
# $ curl http://date.jsontest.com | ./debug_json.rb
r = $stdin.dup
input = r.read
$stdin.reopen("/dev/tty")
require 'json'
require 'recursive-open-struct'
require 'awesome_print'
hash = JSON.parse(input)
obj = RecursiveOpenStruct.new(JSON.parse(input))
require 'pry'
require 'pry-plus'
ap hash # would be cool if this paged
binding.pry
@linkwoman
Copy link

Thanks Gabe. How do I run it? I thought like this:
curl -XPOST 'http://54.81.34.92:8080/UserQueryServer-0.1/rest/elements/query' -d 'nouns=metabolites&verbs=&adjectives=&verbPercentage=.33&nounPercentage=.33&adjectivePercentage=.33&sourceTypes=drug&size=1' > debug_JSON.rb

I get back nothing. The curl works otherwise.

@gkop
Copy link
Author

gkop commented Mar 21, 2014

@linkwoman, replace the > debug_JSON.rb with | ./debug_JSON.rb

@linkwoman
Copy link

I had to rvm gemset use global and gem install all those required gems. Now it works like a charm.
Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment