Skip to content

Instantly share code, notes, and snippets.

@Cinderhaze
Created May 7, 2015 02:51
Show Gist options
  • Save Cinderhaze/33c0a1b70e86ed454a5a to your computer and use it in GitHub Desktop.
Save Cinderhaze/33c0a1b70e86ed454a5a to your computer and use it in GitHub Desktop.
Trying to parse AWS JSON with ruby
I found a good example of how to parse JSON with ruby on stack overflow here => http://stackoverflow.com/a/13625633
For an example of AWS JSON, I found an example at (http://unix.stackexchange.com/questions/121718/how-to-parse-json-with-shell-scripting-in-linux), but I fixed some errors in the json and have a copy here (https://gist.github.com/Cinderhaze/f122232d15eb700449f0)
I put the above json in a file (ec2s.json) and ran 'gem install json'
I have tried the following in IRB
require 'json'
file = File.open('ec2s.json')
contents = file.read
file.close
parsed = JSON.parse(contents)
parsed['Instances'] #This returns me a value that looks about right
#What I want to do now is something like
ip = parsed['Instances']['PrivateIpAddress']
name = parsed['Instances']['Tags']['Name']
[name, ip]
@Cinderhaze
Copy link
Author

Here was my first attempt... let me know what things I did in silly ways! What's the more ruby way of doing this?

https://gist.github.com/Cinderhaze/36039d8521c22e5965ff

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